Active sheet In Excel in .NET

Hi Aspose team,

I am generating my Excel through Apose…
I have 3 Worksheets in my Excel…
How to set my own.Active sheet, when Excel is opened…(that sheet must be shown when excel is opened).
Please reply back asap…


Thanq

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the Workbook.Worksheets.ActiveSheetIndex property for your needs. You can set your desired sheet using this property and MS-Excel will display this sheet on opening the file.

HI,


I used this property Workbook.Worksheets.ActiveSheetIndex=2; but i am unable to open the given Indexed sheet,
i am using trial version of Aspose… It always opens EvaluationWarning Sheet as active sheet…
Is it possible if i purchase Aspose ???
Get BACK to me Asap… please…


Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Well, you cannot change the active sheet index in trial version. You will have to purchase and set license to change the active sheet.

Hi,


I am using licence version but still not able to set 2nd sheet as active sheet by default.

Can you please help me with this?



Thanks in advance :slight_smile:

Hi,

Thanks for your posting and using Aspose.Cells.

Please first set the license and then load your workbook and set the active worksheet using the Workbook.Worksheets.ActiveSheetIndex property.

Please see here how I am setting the license.

I have attached the sample Excel file used in this code and the output Excel file generated by it for your reference. As you can see in the output Excel file, the second worksheet is the active worksheet.

C#


//First set the license

Aspose.Cells.License lic = new Aspose.Cells.License();

lic.SetLicense(@“F:\Aspose.Total.lic”);


//Load your workbook

Workbook workbook = new Workbook(@“F:\Shak-Data-RW\Downloads\sample.xlsx”);


//Set second worksheet as active worksheet, index starts from 0,

//so 1 means 2nd worksheet

workbook.Worksheets.ActiveSheetIndex = 1;


//Save the workbook

workbook.Save(“output.xlsx”);

Hi,


I have set the license

But I need to set 2nd sheet as active after adding the sheet into workbook

and of course before saving the workbook.

Code is:

Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet sheet1 = wb.Worksheets[0];
sheet1.Name = “abc”;

int secondSheet = wb.Worksheets.Add();
Aspose.Cells.Worksheet sheet = wb.Worksheets[secondSheet];
sheet.Name = “xyz”;

wb.Worksheets.ActiveSheetIndex = 1; //Not working

wb.save(“output.xls”);


Can you suggest what exactly i need to add here?

Thanks for the quick reply.

Hi Shahista,


Thank you for providing your code snippet.

We have evaluated your presented scenario while using the latest version of Aspose.Cells for .NET 8.2.1, and was unable to observe any issue. The resultant spreadsheet has active worksheet set to “xyz” that is expected behavior. Please note, you have to set the license before creating an instance of Workbook in order to make your code work as desired. Moreover, if you are using any older version of the API, please give a try to the latest version (link shared above).