1

I have renamed a Worksheet using ClosedXML and I have verified that although the sheet is renamed well, the references inside the sheet does not see the change and the excel document is corrupted. Does anyone know of any method to rename sheets other than using Interop?

workbook.Worksheet("TemplateSheet").Name = "NewSheetName";
Acubo
  • 120
  • 6
  • References for formulas or links? You could loop through them with ClosedXml and update them yourself. – Raidri Mar 13 '20 at 09:38
  • Yes, references in formulas. I wanted something automatic and generic to avoid having to code for every different sheet. For example, Interop implements well this rename, but I cannot use it in my deploys. – Acubo Mar 14 '20 at 10:12

1 Answers1

0

If someone want to change default(in case of Datatable it takes the name of the class you add to it i.e ExcelData here) sheet name.

//custom class
XLWorkbook workbook = new XLWorkbook();
ExcelData ex = new ExcelDate(){CompanyName="StackOverfLow", Stars=5 };
//Add to Datatable
Datatable table = ListToDataTable.ToDataTable(excelReady);
workbook.Worksheets.Add(table, "sheetname"); // Just define your desired sheet name!

//Using this class to add in DataTable
class ExcelData{
   public string CompanyName{get;set;}
   public int Stars{get;set;}
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Yash
  • 369
  • 5
  • 18