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

Hello,

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

@askgowda,

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:
e.g
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();
			options.setImageFormat(ImageFormat.getPng());
                        options.setPrintingPage(PrintingPageType.IGNORE_BLANK);
			
			PageSetup pageSetup = worksheet.getPageSetup();
			pageSetup.setPaperSize(PaperSizeType.PAPER_A_4);
			
			...................
			
			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.

@Amjad_Sahi
Thanks. Yes, this will help.

@askgowda,

You are welcome.