Worksheet panel after saving issue

Hi.


I have found one issue with worksheets panel. After changing active worksheet, panel of worksheet don’t move back to first worksheet


@Test
public void activeWorksheetTest() throws Exception {
Workbook workbook = new Workbook(“D://in.xlsx”);
for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
workbook.getWorksheets().setActiveSheetIndex(i);
workbook.getWorksheets().get(i).getCells().get(0, 0).putValue(i);
}
workbook.getWorksheets().setActiveSheetIndex(0);
workbook.save(“D://out.xlsx”);
}

Best regards. Alexey

Hi,


Please add a line to your code segment before saving the Excel file:
e.g
Sample code:

workbook.getSettings().setFirstVisibleTab(0);

Thank you.

Hi. Thanks it helps, but i don’t understand why first visible tab moves, when i move active sheet to end. And does not whan i moved active sheet to begin.


Best regards. Alexey

Hi,


Good to know that it figures out your issue now. Well, by default, if there are many worksheets, it scrolls to the last part/ portion and displays last few worksheet tabs when you open the file into MS Excel. So, you have to scroll to and make your desired tab visible accordingly for your needs.

Thank you.

Hi.


Is it possible to implement a behavior of sheet selection, like it did for MS Excel.

I have attached the excel file with macroses:
1) scrollSheet18 select a sheet18 and worksheet’s link displayed according with previous position. If we run macro from first sheet, that sheet18 will be last in worksheets bar. If scroll of worksheets bar not required - worksheet will be selected without scroll.
2) scrollSheet2 select a sheet2 and worksheet’s link displayed according with previous position. If we run macro from 18’s sheet, that sheet2 will be first in worksheets bar. If scroll of worksheets bar not required - worksheet will be selected without scroll.

Best regards. Alexey

Hi,


Thanks for the template file.

Please see the document on how to add VBA code/ macros in the Excel spreadsheets:
http://www.aspose.com/docs/display/cellsjava/Adding+VBA+Module+and+Code+using+Aspose.Cells

Aspose.Cells can add/ manipulate macros/ vba codes but does not support to execute macros/vba codes in the template file. Furthermore, you may also try to move a worksheet within a workbook or in b/w workbooks, see the document for your reference here:
http://www.aspose.com/docs/display/cellsjava/Copying+and+Moving+Worksheets

Also, when I run the macro “selectSheet18” in the template file, I got the error, see the screen shot for your reference here:
http://prntscr.com/8sx9ql


Thank you.


Hi. I don’t needed to save macros in Excel. I needed to have same implementation of workbook.setSheet of Aspose’s method. Please check this file


Best regards

Hi,


Thanks for the template file.

Well, you may first try to set your desired active sheet and then set it as first visible tab on sheet tab bar, see the following sample code:
e.g
Sample code:

License license = new License();
license.setLicense(“Aspose.Total.Java.lic”);

Workbook workbook = new Workbook(“sheetscroll.xlsm”);

//Suppose you need to set 4th sheet active and make it first visible sheet in the sheet tab bar.
int index = 3;
workbook.getWorksheets().setActiveSheetIndex(index);
workbook.getSettings().setFirstVisibleTab(index);

workbook.save(“out1.xlsm”);

And, to make the worksheet 17 (active sheet) as the last tab in the sheet tab bar, I am afraid, there is no better way to cope with it and you have to evaluate the total number of sheets in the tab bar, then set the worksheet 17 as an active sheet and finally specify some starting worksheet (e.g Sheet 6/7) as the first visible tab accordingly.

Thank you.