Converting Worksheet to Different Image Formats

Converting Worksheet to Image

Worksheets contain data that you want to analyze. For example, a worksheet can contain parameters, totals, percentages, exceptions, and calculations.

As a developer, you might need to present worksheets as images. For example, you might need to use an image of a worksheet in an application or web page. You might want to insert an image into a Microsoft Word document, a PDF file, a PowerPoint presentation, or some other document type. Simply put, you want a worksheet rendered as an image so that you can use it somewhere else.

Aspose.Cells supports converting Excel worksheets to images. To use this feature, you need to import the Aspose.Cells.Rendering namespace to your program or project. It has several valuable classes for rendering and printing, for example, SheetRenderImageOrPrintOptions, and others.

The Aspose.Cells.Rendering.ISheetRender class represents a worksheet to render as images. It has an overloaded method, ToImage, that can convert a worksheet to image file(s) with different attributes or options. Several image formats are supported, for example, BMP, PNG, GIF, JPG, JPEG, TIFF, and EMF.

The following code snippet shows how to convert a worksheet in an Excel file to an image file.

convert Excel/spreadsheet to PNG with GoLang

Please see the following sample code, its sample Excel file, and the output PNG Images.

workbook, _ := NewWorkbook_String("67338402.xlsx")
worksheets, _ := workbook.GetWorksheets()
worksheet, _ := worksheets.Get_Int(0)
imageOrPrintOptions, _ := NewImageOrPrintOptions()
imageOrPrintOptions.SetImageType(ImageType_Png)
imageOrPrintOptions.SetHorizontalResolution(96)
imageOrPrintOptions.SetVerticalResolution(96)
sheetRender, _ := NewSheetRender(worksheet, imageOrPrintOptions)
stream, _ := sheetRender.ToImage_Int(0)
file, _ := os.OpenFile("67338401.png", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
defer file.Close()
file.Write(stream)

convert Excel/spreadsheet to TIFF with GoLang

Please see the following sample code, its sample Excel file, and the output TIFF Image.

workbook, _ := NewWorkbook_String("67338402.xlsx")
worksheets, _ := workbook.GetWorksheets()
worksheet, _ := worksheets.Get_Int(0)
imageOrPrintOptions, _ := NewImageOrPrintOptions()
imageOrPrintOptions.SetImageType(ImageType_Tiff)
imageOrPrintOptions.SetHorizontalResolution(96)
imageOrPrintOptions.SetVerticalResolution(96)
sheetRender, _ := NewSheetRender(worksheet, imageOrPrintOptions)
stream, _ := sheetRender.ToImage_Int(0)
file, _ := os.OpenFile("67338419.tiff", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
defer file.Close()
file.Write(stream)

convert Excel/spreadsheet to SVG with GoLang

workbook, _ := NewWorkbook_String("67338402.xlsx")
worksheets, _ := workbook.GetWorksheets()
worksheet, _ := worksheets.Get_Int(0)
imageOrPrintOptions, _ := NewImageOrPrintOptions()
imageOrPrintOptions.SetImageType(ImageType_Svg)
imageOrPrintOptions.SetHorizontalResolution(96)
imageOrPrintOptions.SetVerticalResolution(96)
sheetRender, _ := NewSheetRender(worksheet, imageOrPrintOptions)
stream, _ := sheetRender.ToImage_Int(0)
file, _ := os.OpenFile("67338403.svg", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
defer file.Close()
file.Write(stream)

SVG stands for Scalable Vector Graphics. SVG is a specification based on XML standards for two-dimensional vector graphics. It is an open standard that has been under development by the World Wide Web Consortium (W3C) since 1999.

Aspose.Cells for Go via C++ has been able to convert worksheets to SVG images since version 24.12.0.

To use this feature, import the Aspose.Cells.Rendering namespace to your program or project. It has several valuable classes for rendering and printing, for example, ISheetRenderIImageOrPrintOptions, and others.

The Aspose.Cells.Rendering.IImageOrPrintOptions class specifies that the worksheet will be saved in SVG format. The following code snippet shows how to convert a worksheet in an Excel file to an SVG image file

Please see the following sample code, its sample Excel file, and the output SVG Images.