Мне нужно имя листа вместо имени листа по умолчанию
// creating Excel Application Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); // creating new WorkBook within Excel application Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); // creating new Excelsheet in workbook //Microsoft.Office.Interop.Excel._Worksheet worksheet = null; Worksheet worksheet = null; // see the excel sheet behind the program app.Visible = false; // get the reference of first sheet. By default its name is Sheet1. // store its reference to worksheet worksheet = (Worksheet)workbook.Sheets["Sheet1"]; //worksheet = (Worksheet)workbook.Worksheets.get_Item(0); worksheet = (Worksheet)workbook.ActiveSheet; // changing the name of active sheet int m = 1; int totcolumns = ds.Tables[0].Columns.Count; //get column numbers //worksheet.Name = "Sheet1"; ReportsProgress(35, "adding data into new excel file"); #region adding column header DataRow ch = ds.Tables[0].Rows[0]; for (int j = 1; j < totcolumns + 1; j++) //Line added by raghu30082013 { //worksheet.Cells[m, j] = "F" + j.ToString(); worksheet.Cells[m, j] = ch[j-1].ToString(); //Added by Siva (Same column header as source excel) 05 April 2016 } #endregion
Что я уже пробовал:
//worksheet = (Worksheet)workbook.Sheets["Sheet1"]; worksheet = (Worksheet)workbook.Worksheets.get_Item(0);
Member 12878418
здесь по умолчанию лист 1-это упоминание, но мне нужно имя листа