Friday 7 June 2019

How to write to specific cells in an existing Excel (xlsc) file with C#

I managed to read from an Excel file using IExcelDataReader, now I wish to write to specific cells in an existing Excel file, so I need to specify path to the file, column and row where the data should be inserted. I googled and found some examples but there were disputes whether the solutions worked or not. So which is the simplest way of doing this (code examples appriciated). Thanks.


Edit: So I tried doing this:


Excel.Application ExcelObj = new Excel.Application();
Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open("Path", 0, true, 5,"", "", true, Excel.xlWindows, "\t", false, false,0, true);

But get the type or namespace name "Application" does not exist in the namespace Excel.
And the same for "Workbook".


I added the references Microsoft.Office.Interop.Excel and Office. What more do I need?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...