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;
1 foreach (Excel.Worksheet sheet in book.Sheets) 2 { 3 for (int i = 1; i <= sheet.UsedRange.Cells.Rows.Count; i++) 4 { 5 for (int j = 1; j <= sheet.UsedRange.Cells.Columns.Count; j++) 6 { 7 Excel.Range m_objRange = (Excel.Range)sheet.Cells[i, j]; 8 } 9 }10 }
1 m_objRange = sheet .get_Range("A1",missing ); 2 m_objRange.set_Value(missing , "单元格的值");
1 m_objRange = sheet .get_Range("A1", missing ); 2 m_objRange.set_Value(missing , "=SUM(A2:A5)");
1 m_objRange.Font.Bold = true;
1 //保留2位小数2 m_objRange.NumberFormat = "0.00";
1 m_objRange = sheet .get_Range("A1", "B2");2 //设置边框粗细3 m_objRange.Borders.Weight = 2;4 //设置边框样式5 m_objRange.Borders.get_Item(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlDouble;
新闻热点
疑难解答