ワークシートから画像を抽出
Contents
[
Hide
]
Microsoft Excelユーザーはスプレッドシートにイメージを追加できます。Aspose.Cellsを使用すると、Microsoft Excelファイルからイメージを読み取り、ローカルドライブに保存することが可能です。この記事では、Aspose.Cells for Java APIを使用してこれを実現する方法を紹介します。
以下のサンプルコードは、Excelファイルから画像を抽出して保存する方法を示しています。
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(ExtractImagesfromWorksheets.class) + "TechnicalArticles/"; | |
// Open a template Excel file | |
Workbook workbook = new Workbook(dataDir + "book3.xlsx"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the first Picture in the first worksheet | |
Picture pic = worksheet.getPictures().get(0); | |
// Set the output image file path | |
String fileName = "aspose-logo.jpg"; | |
// Note: you may evaluate the image format before specifying the image path | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions printoption = new ImageOrPrintOptions(); | |
// Specify the image format | |
printoption.setImageType(ImageType.JPEG); | |
// Save the image | |
pic.toImage(dataDir + fileName, printoption); |