Generating worksheets (tabs) preview for spreadsheet
Generating worksheets (tabs) preview for spreadsheet
Leave feedback
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:
Load a desired spreadsheet file to the Editor class.
Call the getDocumentInfo() method and specify a password of a loaded spreadsheet in case if this spreadsheet is protected with a password.
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
StringinputPath="Sample.xlsx";// Load spreadsheet file to the Editor constructor
Editoreditor=newEditor(inputPath);{// Get document info for this file
IDocumentInfoinfoUncasted=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
SpreadsheetDocumentInfoinfoSpreadsheet=(SpreadsheetDocumentInfo)infoUncasted;// Get the number of all worksheets
intworksheetsCount=infoSpreadsheet.getPageCount();//Iterate through all worksheets and generate the preview on every iteration
for(intworksheetIndex=0;worksheetIndex<worksheetsCount;worksheetIndex++){// Generate one preview as SVG image by worksheet index
SvgImageoneSvgPreview=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.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.