2

我需要在第 5 行第 1 列中插入文本,在第 5 行第 2 列中插入另一个文本...我该怎么做?以下是正在使用并超出范围异常的代码:

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Worksheet xlWorkSheet2;
Excel.Worksheet xlWorkSheet3;
Excel.Range oRange;

xlApp = new Excel.Application();

xlWorkBook = xlApp.Workbooks.Add(misValue);

xlWorkSheet2 = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet2.Name = "The chart sheet";

xlWorkSheet2.Cells[5, 1] = "First Name";
xlWorkSheet2.Cells[5,2] = "Last Name";  
4

1 回答 1

8

在上面的单元格插入之前,您必须添加一个工作表

Excel.Application excelApplication = new Excel.Application();
Excel.Workbook excelWorkBook = excelApplication.Workbooks.Add();
Excel.Worksheet wkSheetData = excelWorkBook.ActiveSheet;
excelApplication.Cells[5, 2] = "TextField";

我希望这有帮助

于 2013-09-23T07:54:15.917 回答