Access Active Sheet in Excel file in .NET

Hello,

is there a way to determine whether a Worksheet is currently selected or "active" among the Worksheets collection? In Excel Office Automation, you will get this using "ActiveSheet". What's the equivalent?

Thanks.

Hi,

Thank you for considering Aspose.

Well, you may try Workbook.Worksheets.ActiveSheetIndex API to get the index of the active sheet. Also, you can use this index to get the active sheet. Please see the following sample code,

Sample Code:

//Instantiating a Workbook object

Workbook book = new Workbook();


//Open the template workbook

book.Open(@"C:\Excels\workboox.xls");


//get the index of the Active Sheet

int index = book.Worksheets.ActiveSheetIndex;


//Accessing the Active worksheet in the Excel file

Worksheet worksheet = book.Worksheets[index];

Thank You & Best Regards,