424,256 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,256 IT Pros & Developers. It's quick & easy.

I am trying to write code using C# to append some data in excel file in the last empt

P: 1
my code:

Excel.Application excelapp = new Excel.Application();
Excel.Workbook`enter code here` excelbook;
string path = "mypath";
excelbook = excelapp.Workbooks.Open(path, 0, False,
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.xlCellTypeLast Cell).Activate();

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

// The Error is here underline .Range
excelsheet.Range(newcelladdress).Value = "New Data";
Sep 30 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.