Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Mar 14, 2023 3:15 pm

I've got a workbook with Spire.Xls .NET and 3 sheets:
1. worksheet
2. worksheet
3. chartsheet

Now, I'd like to reposition the chartsheet to position 2, so that the full list of sheet looks like in following:
1. worksheet
2. chartsheet
3. worksheet

These are my current pain points:
1. REQUIRED: I've found the WorkSheets collection and the ChartSheets list, but I haven't found any property to access MS Excel's property "Sheets" which provides the full list of sheets (worksheets + chartsheets). This property is required to get all sheets in their order.
2. OPTIONAL: The chartsheet class provides property "Index", which is always 0 in my example above, since my chartsheet is the only one in the whole workbook, so it's always the very first one of all chartsheets. But I need a property to lookup the index in the all-sheets-colleciton. For sure, this property is required for class worksheet, too. (This feature is optional, since index position in sheets collection could be detected from property Workbook.Sheets, see point 1)
3. REQUIRED: method MoveToSheetIndex is required for both ChartSheet and WorkSheet. Currently, class Worksheet already implements method MoveWorksheet, but it only moves inside the worksheets collection; there is no option for moving inside the sheets collection. ChartSheet doesn't provide such a method at all.

compumaster
 
Posts: 1
Joined: Fri Jun 25, 2021 11:37 am

Wed Mar 15, 2023 7:32 am

Hello,

Thanks for your inquiry.
According to your description, please use the following code to implement your requirements.
Code: Select all
  //Get the chartsheet index in Microsoft Sheets
  int chartsheetIndex = workbook.Chartsheets[0].RealIndex;
  // Move the position of the chartsheet
  workbook.Chartsheets[0].RealIndex = 1;
  //Get the Worksheet index in Microsoft Sheets
  int worksheetIndex =  workbook.Worksheets[1].RealIndex;

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS