I made some sheets in an Excel file. I made a lot at the same time with this code:
newSheet2 = (Microsoft.Office.Interop.Excel._Worksheet)newWorkbook_First.Sheets.Add(Type.Missing,Type.Missing,5,Type.Missing);
...But I don't know how to name them individually. I thought it had to do it this way:
newSheet2[2].name = "hello"
But this gave an error. How can I do this?
private static Microsoft.Office.Interop.Excel.ApplicationClass appExcel;
private static Workbook newWorkbook_First = null;
private static _Worksheet newSheet2 = null;
public void excel_create(String path)
{
try
{
appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
appExcel.Visible = true;
newWorkbook_First = appExcel.Workbooks.Add(1);
newSheet2 = (Microsoft.Office.Interop.Excel._Worksheet)newWorkbook_First.Sheets.Add(Type.Missing,Type.Missing,5,Type.Missing);
//How to name the sheets now?
}
catch (Exception e)
{
Console.Write("Error");
}
finally
{
}
}
You were close, use 'Name', not 'name':