Based on. NET Excel Development: operation of cell ranges (reading, assignment, borders, and formatting)

Source: Internet
Author: User
Tags dashed line ranges

    • Reference
using Excel = Microsoft.Office.Interop.Excel;

    • Defined
1 Excel.applicationclass app; 2 excel.workbooks Books; 3 Excel.Workbook Book; 4 excel.sheets Sheets; 5 Excel.Worksheet sheet; 6 Excel.Range m_objrange; 7 object missing = System.Reflection.Missing.Value;

    • Read valid range of cells
1 foreach(Excel.Worksheet sheetinchBook . Sheets)2 {3      for(inti =1; I <= sheet. UsedRange.Cells.Rows.Count; i++)4     {5          for(intj =1; J <= Sheet. UsedRange.Cells.Columns.Count; J + +)6         {7Excel.Range m_objrange =(excel.range) sheet. Cells[i, j];8         }9     }Ten}

    • Cell range Assignment
1 m_objrange = sheet. Get_range (the value of the"A1"2" cell ");

    • Cell range Settings Excel formula
1 m_objrange = sheet. Get_range ("A1"2"=sum (A2: A5)");

    • Font Bold
1 true;

    • Set Number format
1 // Keep 2 decimal places 2 " 0.00 ";

    • Set border
1  m_objrange = sheet. Get_range ( "  A1   ", "  b2  "  );  2  //  set border weight  3  m_objRange.Borders.Weight = 2  ;  4  //  set border style  5  M_objRange.Borders.get_Item ( EXCEL.XLBORDERSINDEX.XLEDGETOP). LineStyle = Excel.XlLineStyle.xlDouble; 

    • XlLineStyle Enumeration
Xlcontinuous: Solid line.

Xldash: Dashed line. Xldashdot: Point and Cross Line. Xldashdotdot: Dash followed by two points. Xldot: Dot line. Xldouble: Double line. Xllinestylenone: No lines.

Xlslantdashdot: Slanted Dash.
    • XlBordersIndex Enumeration
Xldiagonaldown: Diagonal, from upper left corner to bottom right corner. Xldiagonalup: Diagonal, from upper left corner to bottom right corner. Xledgebottom: Bottom Border. Xledgeleft: Left border.

Xledgeright: Right border.

Xledgetop: Top Border. Xlinsidehorizontal: Internal horizontal border. Xlinsidevertical Vertical: Internal vertical border.

The

is based on. NET Excel Development: operation of a cell range (read, assign, border, and format)

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.