ワークシートから画像へ、ワークシートから画像へのページ単位での変換

Aspose.Cells を使用してワークシートを画像ファイルに変換する

この記事では、Aspose.Cells for Java API を使用してワークシートを画像に変換する方法を示します。 API は、次のようないくつかの価値のあるクラスを提供します。シートレンダリングImageOrPrintOptionsWorkbookRender 、 等々。のシートレンダリングクラスは、ワークシートの画像をレンダリングするためのワークシートを表し、オーバーロードされた[toImage](https://reference.aspose.com/cells/java/com.aspose.cells/sheetrender#toImage(int,%20java.io.OutputStream)任意の属性またはオプション セットを使用して、ワークシートを画像ファイルに直接変換できるメソッド。

// 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(ConvertWorksheettoImageFile.class) + "TechnicalArticles/";
// Create a new Workbook object
// Open a template excel file
Workbook book = new Workbook(dataDir + "book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Specify the image format
imgOptions.setImageType(ImageType.JPEG);
// Render the sheet with respect to specified image/print options
SheetRender render = new SheetRender(sheet, imgOptions);
// Render the image for the sheet
render.toImage(0, dataDir + "CWToImageFile.jpg");

結果

上記のコードを実行すると、Sheet1 という名前のワークシートが画像ファイル SheetImage.jpg に変換されます。

出力JPG

todo:画像_代替_文章

Aspose.Cells を使用してワークシートをページごとに画像ファイルに変換する

この例では、Aspose.Cells を使用して、複数ページのテンプレート ワークブックからワークシートをページごとに 1 つのイメージ ファイルに変換する方法を示します。

// 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(ConvertWorksheetToImageByPage.class) + "TechnicalArticles/";
// Create a new Workbook object
// Open a template excel file
Workbook book = new Workbook(dataDir + "ConvertWorksheetToImageByPage.xlsx");
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Define ImageOrPrintOptions
ImageOrPrintOptions options = new ImageOrPrintOptions();
// Set Resolution
options.setHorizontalResolution(200);
options.setVerticalResolution(200);
options.setImageType(ImageType.TIFF);
// Sheet2Image by page conversion
SheetRender render = new SheetRender(sheet, options);
for (int j = 0; j < render.getPageCount(); j++) {
render.toImage(j, dataDir + sheet.getName() + " Page" + (j + 1) + ".tif");
}

結果

上記のコードを実行すると、Sheet1 という名前のワークシートが 2 つの画像ファイル (1 ページに 1 つ) に変換されます。Sheet 1 Page 1.Tiff と Sheet 1 Page 2.Tiff です。

生成された画像ファイル (Sheet 1 Page 1.Tiff)

todo:画像_代替_文章

生成された画像ファイル (Sheet 1 Page 2.Tiff)

todo:画像_代替_文章

関連記事