Excelワークシートの透過画像を作成
Contents
[
Hide
]
場合によっては、ワークシートの画像を透明な画像として生成する必要があります。塗りつぶしの色がないすべてのセルに透明度を適用します。 Aspose.Cells はImageOrPrintOptions.setTransparent()ワークシート イメージに透明度を適用するプロパティ。このプロパティが間違いの場合、塗りつぶしの色のないセルは白色で描画されます。真実、塗りつぶしの色のないセルは透明に描画されます。
次のワークシート イメージでは、透明度が適用されていません。塗りつぶしの色がないセルは白で描画されます。
透明度を適用しないワークシート イメージ
一方、次のワークシート イメージでは、透明度が適用されています。塗りつぶしの色がないセルは透明です。
透明度適用後のワークシート イメージ
次のサンプル コードを使用して、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(CreateTransparentImage.class) + "TechnicalArticles/"; | |
// Create workbook object from source file | |
Workbook wb = new Workbook(dataDir + "aspose-sample.xlsx"); | |
// Apply different image or print options | |
ImageOrPrintOptions imgOption = new ImageOrPrintOptions(); | |
imgOption.setImageType(ImageType.PNG); | |
imgOption.setHorizontalResolution(200); | |
imgOption.setVerticalResolution(200); | |
imgOption.setOnePagePerSheet(true); | |
// Apply transparency to the output image | |
imgOption.setTransparent(true); | |
// Create image after apply image or print options | |
SheetRender sr = new SheetRender(wb.getWorksheets().get(0), imgOption); | |
sr.toImage(0, dataDir + "CTransparentImage_out.png"); |