Introduction
As we all know, Worksheets typically contain data that is associated in some way but organized to show different perspectives. For example, you might want to analyze different aspects of sales performance and create different worksheets for each aspect. Worksheets contain data that you want to analyze for your requirements. For example, a worksheet can contain parameters, totals, percentages, exceptions, and calculations.
At times, you might require to present your worksheets as a pictatorial representation. you do need to present the worksheet images into your applications or web pages. You might need to insert the images into a Word Document, a PDF file, a Power Point Presentation or in some other scenario. Simply you want the worksheet should be rendered as an image, so that you may paste it into your applications with ease.
Since v4.5, Aspose.Cells supports to convert Worksheets in Excel files to images.
The overloaded SheetToImage method of the Worksheet class converts a worksheet to an image file specified with your desired attributes e.g., ImageFormat type, paginated sheets etc. It can return System.Drawing.Bitmap object. This object has a Save method used to save the image file to disk. The following image formats are supported:
.bmp, .gif, .jpg, .jpeg, .tiff, .emf.
Example:
The following example shows how to convert a worksheet in an excel file to render an image file.
[C#]
//Create a new Workbook object.
Workbook book = new Workbook();
//Open a template excel file.
book.Open("D:\\test\\testBook.xls");
//Get the first worksheet.
Worksheet sheet = book.Worksheets[0];
//Convert the worksheet to image.
Bitmap bitmap = sheet.SheetToImage();
//Save the image file specifying its image format.
bitmap.Save(@"d:\SheetImage.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
[VB]
'Create a new Workbook object.
Dim book As Workbook = New Workbook()
'Open a template excel file.
book.Open("D:\test\testBook.xls")
'Get the first worksheet.
Dim sheet As Worksheet = book.Worksheets(0)
'Convert the worksheet to image.
Dim bitmap As Bitmap = sheet.SheetToImage()
'Save the image file specifying its image format.
bitmap.Save("d:\SheetImage.jpg",System.Drawing.Imaging.ImageFormat.Jpeg)
[JAVA]
Currently this feature is not available in Java version, we will support it in the future.