C # How do I draw a diagonal line in a cell in EXCEL ??,

Source: Internet
Author: User

C # How do I draw a diagonal line in a cell in EXCEL ??,
Code Snippet

Practice:

1. First add reference COM and find Excel

2, using Excel = Microsoft. Office. Interop. Excel;

3,

Code

Private Excel. Application m_objExcel = null;
Private Excel. Workbooks m_objBooks = null;
Private Excel. _ Workbook m_objBook = null;
Private Excel. Sheets m_objSheets = null;
Private Excel. _ Worksheet m_objSheet = null;
Private Excel. Range m_objRange = null;

Private object m_objOpt = System. Reflection. Missing. Value;

 

Private void button3_Click (object sender, EventArgs e)
{
M_objExcel = new Excel. Application ();
M_objExcel.Visible = false;
M_objExcel.DisplayAlerts = false;

If (m_objExcel.Version! = "11.0 ")
{
MessageBox. Show ("your Excel version is not 11.0 (Office 2003), and operations may fail. ");
M_objExcel.Quit ();
Return;
}

M_objBooks = (Excel. Workbooks) m_objExcel.Workbooks;

M_objBook = require (@ "E: \ WebSite2 \ Book2.xls", m_objOpt, empty, empty, m_objOpt, merge, merge, and merge, m_objOpt );

M_objSheets = (Excel. Sheets) m_objBook.Worksheets;
M_objSheet = (Excel. _ Worksheet) (m_objSheets.get_Item (1 ));
M_objRange = m_objSheet.get_Range ("B3", m_objOpt );
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlDiagonalDown]. LineStyle = Excel. XlLineStyle. xlLineStyleNone;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlDiagonalUp]. LineStyle = Excel. XlLineStyle. xlContinuous;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlDiagonalUp]. ColorIndex = Excel. XlColorIndex. xlColorIndexAutomatic;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlEdgeLeft]. LineStyle = Excel. XlLineStyle. xlLineStyleNone;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlEdgeTop]. LineStyle = Excel. XlLineStyle. xlLineStyleNone;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlEdgeBottom]. LineStyle = Excel. XlLineStyle. xlLineStyleNone;
M_objRange.Borders [Microsoft. Office. Interop. Excel. XlBordersIndex. xlEdgeRight]. LineStyle = Excel. XlLineStyle. xlLineStyleNone;
M_objBook.Save ();

M_objBook.Close (false, m_objOpt, m_objOpt );
M_objExcel.Quit ();

This. DisposeExcel ();
}

 

 

 

/// <Summary>
/// Release the referenced COM object. Note: This process must be executed.
/// </Summary>
Public void DisposeExcel ()
{

ReleaseObj (m_objSheets );
ReleaseObj (m_objBook );
ReleaseObj (m_objBooks );
ReleaseObj (m_objExcel );
System. GC. Collect ();
System. GC. WaitForPendingFinalizers ();
}
Private void ReleaseObj (object o)
{
Try
{
System. Runtime. InteropServices. Marshal. ReleaseComObject (o );
}
Catch {}
Finally {o = null ;}
}

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.