| Sometimes, it is useful to save a picture of a worksheet. Images can be shared online, inserted into other documents (reports written in Microsoft Word, for example, or PowerPoint presentations).
Aspose.Cells provides image export through the SheetRender class. The SheetRender class represents the worksheet that will be rendered to an image. The SheetRender class provides the toImage() method for converting a worksheet to an image file. BMP, PNG, JPEG and EMF formats are supported. |
Example
The code below shows how to convert a worksheet in an Excel file to a PNG file.
[Java]
//Instantiate a new workbook with path to an Excel file Workbook book = new Workbook("e:\\test\\Book1.xls"); //Create an object for ImageOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Set the image type imgOptions.setImageFormat(ImageFormat.getPng()); //Get the first worksheet. Worksheet sheet = book.getWorksheets().get(0); //Create a SheetRender object for the target sheet SheetRender sr = new SheetRender(sheet, imgOptions); for (int j = 0; j < sr.getPageCount(); j++) { //Generate an image for the worksheet sr.toImage(j, "d:\\files\\mysheetimg_" + j + ".png"); }
