Since you're creating a Word Add-In, you'll need to open another instance of Excel, and then create the Excel Worksheet. Here's a quick example:
Excel.Application xlApp = new Excel.Application();
if (xlApp == null)
{
Console.WriteLine("Excel could not be started. Check that your office installation and project references are correct.");
return;
}
xlApp.Visible = true;
Excel.Workbook wb = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
if (ws == null)
{
Console.WriteLine("Worksheet could not be created. Check that you office installation and project references are correct.");
}
for(int i = 1; i < 5; i++)
{
ws.Range["A" + i.ToString()].Value = i * (i + 1);
}
wb.SaveAs(Filename: "C:\\temp\\test.xlsx");
This also assumes that you've added the appropriate using statement: using Excel = Microsoft.Office.Interop.Excel;
as well as added a reference to the Excel Interop.