Worksheet Positioning

Hi,

I wanted to know how can I set the first Worksheet as the current active? thing is that when I generate the workbook the las Worksheet is currently the one active but I wanted it to be the first Worksheet in the Workbook.

Thank you!

Marcos

Hi,

Thanks for your posting and considering Aspose.Cells.

Please use the following code to activate the worksheet of your desired position.

C#


workbook.Worksheets.ActiveSheetIndex = 0; //will activate first worksheet

workbook.Worksheets.ActiveSheetIndex = 1; //will activate second worksheet

Thank for the reply... It's not working tough... is there any other way of doing this? or should be a reason for this piece of code not to be working?

Thanks,

Marcos

Hi,

Please see the source and output file and the code below.

Please see the screenshot. As you can see, it is working fine.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


workbook.Worksheets.ActiveSheetIndex = 1; //will activate second worksheet


workbook.Save(filePath + “.out.xlsx”);

Screenshot

Hi,


For activating worksheets in a workbook, you need to have a valid license (for Aspose.Cells product) and set it in your sample code before using the sample code(see the topic for your reference: http://docs.aspose.com/display/cellsnet/Licensing). If you do not set the license in your code the last worksheet “Evaluation Watermark worksheet” would be active by default I am afraid.

See the topic for your reference:
http://docs.aspose.com/display/cellsnet/Activating+Sheets+and+Making+an+Active+Cell+in+the+Worksheet

Thank you.

Thanks for the info... the worksheet is being set to first place but now I have the problema that in the navigation bar at the bottom I have some other worksheets and the is not the one I set as first with your code, how can I set the order or positioning worksheets in the bottom navigation bar?

Thanks!

Marcos

Hi,


Well, I think you need to move a worksheet in the workbook, you may use Worksheet.Move() method, e.g
Worksheet.Move(0)–> it will place it to the first position in the workbook.

See the topic for your complete reference about Moving worksheets and copying worksheets:
http://docs.aspose.com/display/cellsnet/Copying+and+Moving+Worksheets

Thank you.