Currently, I have some code that is able to create the file, create new worksheets, change the active worksheet, but it won't write to the cells. Below is my code:
var excelApp = new Excel.Application
{
Visible = false,
ScreenUpdating = false
};
object misValue = System.Reflection.Missing.Value;
var workbook = excelApp.Workbooks.Add(misValue);
var worksheets = workbook.Worksheets;
var worksheet = (Excel.Worksheet)workbook.ActiveSheet;
worksheet.Cells[3, 3].Value2 = "123"; //This is the part where I'm struggling
workbook.SaveAs(completePathToFile, Excel.XlFileFormat.xlWorkbookNormal);
workbook.Close();
How it currently is, it throws:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot perform runtime binding on a null reference'
Which makes little sense as to why it would throw that when I'm trying to set its value to not null. I have also tried removing the Value2 and just setting the cell directly. The error goes away, but it still doesn't write to the .xls file.