We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Retrieve the worksheet name from a given page number


I’m using Aspose cells for Java v19.8 for rendering the excel files into PNG images.
Given a page number, is it possible to retrieve the worksheet name for which it belongs to?

For instance, assume a sample excel document contains 10 worksheets. When we render this document into PNG files (one page per PNG), lets say we get 50 pages.
Now, I need to figure out the name of the worksheet for which the page no 34 belongs to.

Please note, I’m using
options.setPrintingPage(PrintingPageType.IGNORE_BLANK); and worksheet.getPageSetup().setPrintArea(printArea) for rendering


Thanks for your query.

Well, you may easily do it. Since SheetRender object is instantiated based on specific Worksheet, so you may get the name of the sheet, see the sample code for your reference:
Sample code:

Workbook book = new Workbook("Book1.xlsx");
	for (int sheetIndex = 0; sheetIndex < book.getWorksheets().getCount(); sheetIndex++) {
		Worksheet worksheet = (Worksheet) book.getWorksheets().get(sheetIndex);
		if (worksheet.isVisible()) {
			ImageOrPrintOptions options = new ImageOrPrintOptions();
			PageSetup pageSetup = worksheet.getPageSetup();
			SheetRender sr = new SheetRender(worksheet, options);
                        String sheetName = worksheet.getName();
			for (int pageIndex = 0; pageIndex < sr.getPageCount(); pageIndex++) {
				sr.toImage(pageIndex, "c:/temp/sheet_" + sheetName + "_" + pageIndex + ".png");

Hope, this helps a bit.

Thanks. Yes, this will help.


You are welcome.