I am using this Excel object to write data to my current spreadsheet:
Excel.Application tApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
My Issue:
It works only when I have my excel spreadsheet opened but it does not work if I do not open the spreadsheet manually.
I added some codes to open the spreadsheet, but it did not work either. Besides, I do not want to open / save and close the spreadsheet for each iteration.
Here is the code example:
Excel.Application eApp = new Excel.ApplicationClass();
eApp.Visible = true;
string workbookPath = "c:\\abc.xlsx";
Excel.Workbook excelWorkbook = eApp.Workbooks.Open(workbookPath);
eApp = null;
I even used this as a standalone test case to avoid opening each time for multiple iterations, but it did not work either.
What I am doing wrong here? I appreciate your help.
Issue wrting data to an excel during runtime
Re: Issue wrting data to an excel during runtime
If you use System.Runtime.InteropServices you need a running instance of Excel. As you just wanna write data without open/save/close the Excel application you should use Microsoft.Office.Interop.Excel like shown in the example here:
https://msdn.microsoft.com/en-us/librar ... s.80).aspx
Have fun!
https://msdn.microsoft.com/en-us/librar ... s.80).aspx
Have fun!
Re: Issue wrting data to an excel during runtime
Thanks. the way I wrote also working now . Not sure why it didn't work earlier.