Generating worksheets (tabs) preview for spreadsheet
Generating worksheets (tabs) preview for spreadsheet
Leave feedback
On this page
Starting from version 23.4, the GroupDocs.Editor for .NET 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 .NET 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 .NET: 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 .NET 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 filestringinputPath="Sample.xlsx";// Load spreadsheet file to the Editor constructorusing(GroupDocs.Editor.Editoreditor=newEditor(inputPath)){// Get document info for this fileIDocumentInfoinfoUncasted=editor.GetDocumentInfo(null);//Make sure it is really a Spreadsheet of XLSX formatAssert.AreEqual(Formats.SpreadsheetFormats.Xlsx,infoUncasted.Format);// Cast this document info to the SpreadsheetDocumentInfo typeSpreadsheetDocumentInfoinfoSpreadsheet=(SpreadsheetDocumentInfo)infoUncasted;// Get the number of all worksheetsintworksheetsCount=infoSpreadsheet.PageCount;//Iterate through all worksheets and generate the preview on every iterationfor(intworksheetIndex=0;worksheetIndex<worksheetsCount;worksheetIndex++){// Generate one preview as SVG image by worksheet indexSvgImageoneSvgPreview=infoSpreadsheet.GeneratePreview(worksheetIndex);// Save SVG preview to the fileoneSvgPreview.Save(Path.Combine(outputFolder,oneSvgPreview.FilenameWithExtension));}}
Concluding, the new worksheets preview feature is by its essence a new public method in the existing 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 System.IO.Stream.
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.