创建 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"); |