|
我对这个菜鸟一枚,能读出来就能写进去呀!
- private void GetWriteExcel()
- {
- List<string[]> list = new List<string[]>();
- list.Add(new string[3] { "a", "b", "c" });
- list.Add(new string[3] { "e", "f", "g" });
- Microsoft.Office.Interop.Excel.Application app = null;
- try
- {
- app = new Microsoft.Office.Interop.Excel.Application();
- Microsoft.Office.Interop.Excel.Workbook workbook = app.Workbooks.Open(@"E:\工作表.xlsx");
- Worksheet worksheet = workbook.Sheets["Sheet1"];
- int row = worksheet.Range["a1"].CurrentRegion.Rows.Count+1;
- foreach (string[] item in list)
- {
- worksheet.Cells[row, 1].value = item[0];
- worksheet.Cells[row, 2].value = item[1];
- worksheet.Cells[row, 3].value = item[2];
- row += 1;
- }
- worksheet = null;
- workbook.Save();
- workbook.Close();
- }
- catch (Exception ex)
- {
- ex.Message.ToString();
- }
- finally
- {
- app.Quit();
- }
- }
复制代码 |
评分
-
1
查看全部评分
-
|