423,485 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,485 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,
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.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";
2 Weeks Ago #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.