当我尝试将数据附加到Excel文件中时出错

时间:2018-09-30 22:29:53

标签: c# excel

我正在尝试使用C#编写代码以在Excel文件的最后一个空行中附加一些日期,但是在涉及范围的代码的最后一行中出现错误。

// my code:

Excel.Application excelapp = new Excel.Application();
Excel.Workbook`enter code here` excelbook;
string path = "mypath";
excelbook = excelapp.Workbooks.Open(path, 0, False, 
5,System.Reflection.Missing.Value, 
System.Reflection.Missing.Value,False, 
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,True, False, 
System.Reflection.Missing.Value, False);

Excel.Sheets excelsheets = excelbook.Sheets;
Excel.Worksheet excelsheet = excelsheets[1];
Excel.Range range = excelsheet.UsedRange;

range.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Activate();

Int32 newrow = excelapp.ActiveCell.Row + 1;
string newcelladdress = "A"  +newrow;

// The Error is here underline .Range
excelsheet.Range(newcelladdress).Value = "New Data";

0 个答案:

没有答案