所定の幅と高さでワークシートまたはグラフをイメージにエクスポート
Contents
[
Hide
]
Aspose.Cellsを使用して、所定の幅と高さでワークシートまたはグラフをイメージにエクスポートできます。エクスポートされるイメージの幅と高さを指定するためのImageOrPrintOptions.setDesiredSize() メソッドを提供します。幅と高さはピクセル単位で指定されます。
所望の幅と高さでワークシートを画像にエクスポート
次のコードは、400x400のサイズでワークシートをイメージにエクスポートします。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExportWorksheettoImage.class) + "TechnicalArticles/"; | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
/* | |
* Set image or print options, We want one page per sheet, The image format is in png And desired dimensions are | |
* 400x400 | |
*/ | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setOnePagePerSheet(true); | |
opts.setImageType(ImageType.PNG); | |
opts.setDesiredSize(400, 400); | |
// Render sheet into image | |
SheetRender sr = new SheetRender(worksheet, opts); | |
sr.toImage(0, dataDir + "EWSheetToImage_out.png"); |