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