using Excel = Microsoft.Office.Interop.Excel;
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}
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)");
1 true;
1 // Keep 2 decimal places 2 " 0.00 ";
1 m_objrange = sheet. Get_range ("A1""B2"); 2 // Set Border thickness 3 2 ; 4 // Set Border Style 5 M_objRange.Borders.get_Item (EXCEL.XLBORDERSINDEX.XLEDGETOP). LineStyle = Excel.XlLineStyle.xlDouble;
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.