我正在尝试在代码中使用C#所有内容在Excel工作表中插入数据,并且运行正常,但数据未插入Excel工作表中。
提示:我使用相同的代码在另一个Excel工作表中插入了另一个数据,并成功插入了数据。
答案 0 :(得分:0)
尝试以下代码
var excelApp = new Excel.Application();
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(@"Excel.xlsx");
Excel._Worksheet excelWorkSheet = (Excel._Worksheet)excelWorkbook.Sheets[1];
excelWorkSheet = (Excel._Worksheet)excelApp.ActiveSheet;
Excel.Range excelRange = excelWorkSheet.UsedRange;
int rowCount = excelRange.Rows.Count;
excelApp.Visible = true;
excelWorkSheet.Cells[1, "A"] = "Insert";
excelWorkSheet.Cells[1, "B"] = "your";
excelWorkSheet.Cells[1, "C"] = "text";
excelWorkSheet.Cells[1, "D"] = "here";
excelWorkbook.Close(true, "output.xlsx");
excelApp.Quit();