我正在尝试使用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";