Create Transparent Image of Excel Worksheet
Contents
[
Hide
]
ワークシートの画像を透明なイメージとして生成する必要があることがあります。塗りつぶし色のないすべてのセルに透明性を適用したい場合があります。Aspose.Cells は、ワークシート画像に透明性を適用するためのImageOrPrintOptions.setTransparent()プロパティを提供しています。このプロパティがfalseの場合、塗りつぶし色のないセルは白色で描画され、trueの場合、塗りつぶし色のないセルは透明に描画されます。
以下のワークシートイメージでは、透明性が適用されていません。埋められていないセルは白色で描画されます。
透明度を適用しないワークシート画像
以下のワークシート画像では、透明度が適用されました。塗りつぶしのないセルは透明です。
透明度を適用した後のワークシート画像
次のサンプルコードを使用して、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"); |