Generating worksheets (tabs) preview for spreadsheet

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:

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
using (GroupDocs.Editor.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.AreEqual(Formats.SpreadsheetFormats.Xlsx, infoUncasted.Format);

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

	// Get the number of all worksheets
	int worksheetsCount = infoSpreadsheet.PageCount;

	//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(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.

On this page