The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
LRLokesh R Syncfusion Team May 20, 2011 03:57 AM UTC
Hi Shrimpy,
Thank you very much for your interest in Syncfusion products.
As you have reported in your last update the code snippet will result with two worksheets in the output file. Because the code will remove from the starting index 0, so when the 0th index is removed, sheet in the 1st index will be moved to the 0th index but the code will remove from the 1st index [But actually you are removing the 2nd index sheet ]. I hope the input workbook has 5 sheets the code will remove in the below way
0 1 2 3 4 0 1 2 3 [When i==0] 0 1 2 [When i==1] 0 1 [When i==2] I have modified the code snippet and placed below, please try the below code snippet at your side and let me know if this helps you.
[C#] // Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine();
// Instantiate the Excel application object. IApplication application = excelEngine.Excel;
string file = @"..\..\Book1.xlsx";
//Open the workbook IWorkbook workbook = application.Workbooks.Open(file, ExcelOpenType.Automatic);
//Delete worksheets from workbook for (int i = workbook.Worksheets.Count - 1; i > 0; i--) workbook.Worksheets.Remove(i);
//Save the workbook workbook.SaveAs("SampleOutput_NoSheetIndex.xlsx");
Please let me know if you need any clarifications.