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;