Rename worksheet
You didn't spedify how do you access the excel file. However, example from here might be useful for you if you're using Microsoft.Office.Interop.Excel. Note that it opens first sheet in the file, line: (Worksheet)xlBook.Worksheets.get_Item(1)
using Excel = Microsoft.Office.Interop.Excel;
object oMissing = System.Reflection.Missing.Value;
Excel.ApplicationClass xl=new Excel.ApplicationClass();
Excel.Workbook xlBook;
Excel.Worksheet xlSheet;
string laPath = Server.MapPath(@"\excel\xl_table.xls");
xlBook = (Workbook)xl.Workbooks.Open(laPath,oMissing,
oMissing,oMissing,oMissing ,oMissing,oMissing,oMissing
,oMissing,oMissing,oMissing,oMissing,oMissi ng,oMissing,oMissing);
xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
xlSheet.Name = "CIAO";
xlBook.Save();
xl.Application.Workbooks.Close();
can try below also
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Worksheet)xlApp.Worksheets["Sheet1"];
worksheet.Name = “NewTabName”;
Add new worksheet after all worksheets
workbook.Sheets.Add(After: workbook.Sheets[workbook.Sheets.Count]);
No comments:
Post a Comment