Reputation: 437
My worksheet is initially named in the 5th line of my code, but I want to rename it based off the workbook name in my case statement. It is not getting renamed. How to fix??
DateTime d = DateTime.Today;
string s = d.ToString("MMddyyyy");
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet objWorksheet = pck.Workbook.Worksheets.Add("Sheet 1");
objWorksheet.Cells["A1"].LoadFromDataTable(dataTable, true);
switch (pageName)
{
case "abcd":
worksheetName = "abcd";
workbookName = "abcd_" + s + ".xlsx";
objWorksheet.Cells["A1:K20"].AutoFitColumns();
break;
}
}
Upvotes: 1
Views: 6673
Reputation: 38392
Looks like you are modifying some unrelated local variable. You would need to modify the Name property on the sheet object:
objWorksheet.Name = "abcd";
Upvotes: 6