Generating worksheets (tabs) preview for spreadsheet

On this page

Starting from version 23.9, the GroupDocs.Editor for Java allows to generate a preview for any worksheet (a.k.a. tab) in the spreadsheet (a.k.a. workbook) document in SVG format. With this feature the end-users are able to view and inspect the content of the spreadsheet without actually sending it for edit. This generated worksheet preview cannot be edited using the GroupDocs.Editor for Java itself, but it can be saved and then viewed in any desktop or online image viewer as well in the browser (because any modern browser actually supports viewing of SVG format).

This feature is working regardless of the licensing mode of the GroupDocs.Editor for Java: it works the same for both trial and licensed mode, there are no trial limitations for this feature. While generating the worksheets preview, the GroupDocs.Editor doesn’t write off the consumed bytes or credits.

Excel spreadsheets may have the so-called hidden worksheets, — GroupDocs.Editor for Java generates an SVG preview for them too.

For generating the worksheets preview for a particular spreadsheet document the user must perform the next steps:

The code sample below shows opening an unprotected spreadsheet file, obtaining a number of all worksheets inside this spreadsheet, and then generating the previews for every worksheet in a loop. Then these previews are saved to the disk.

// Obtain a valid full path to the spreadsheet file
String inputPath = "Sample.xlsx";

// Load spreadsheet file to the Editor constructor
Editor editor = new Editor(inputPath);
{
	// Get document info for this file
	IDocumentInfo infoUncasted = editor.getDocumentInfo(null);

	//Make sure it is really a Spreadsheet of XLSX format
	Assert.assertEquals(SpreadsheetFormats.Xlsx, infoUncasted.getFormat());

	// Cast this document info to the SpreadsheetDocumentInfo type
	SpreadsheetDocumentInfo infoSpreadsheet = (SpreadsheetDocumentInfo)infoUncasted;

	// Get the number of all worksheets
	int worksheetsCount = infoSpreadsheet.getPageCount();

	//Iterate through all worksheets and generate the preview on every iteration
	for (int worksheetIndex = 0; worksheetIndex < worksheetsCount; worksheetIndex++)
	{
		// Generate one preview as SVG image by worksheet index
		SvgImage oneSvgPreview = infoSpreadsheet.generatePreview(worksheetIndex);

		// Save SVG preview to the file
		oneSvgPreview.save("Sample_out_image"+worksheetIndex+"."+ oneSvgPreview.getFilenameWithExtension()));
	}
}

Concluding, the new worksheets preview feature is by its essence a new public method in the existing com.groupdocs.editor.metadata.SpreadsheetDocumentInfo struct, that obtains a worksheet index and returns an instance of SvgImage class. If the end-user needs to obtain a preview of the worksheet in a raster format, but not in the vector, he can use the saveToPng method in the SvgImage class — this method converts the SVG content of the current SvgImage to the PNG format and saves it to the specified OutputStream.

On this page