创建 Excel 工作表的透明图像
Contents
[
Hide
]
有时,您需要将工作表的图像生成为透明图像。您想要对所有没有填充颜色的单元格应用透明度。 Aspose.Cells 提供了ImageOrPrintOptions.透明属性将透明度应用于工作表图像。当这个属性是错误的 然后没有填充颜色的单元格用白色绘制,当它是真的没有填充颜色的单元格被绘制成透明的。
在下面的工作表图像中,没有应用透明度。没有填充颜色的单元格被绘制成白色。
不透明的输出:单元格背景为白色 |
---|
![]() |
同时,在下面的工作表图像中,应用了透明度。没有填充颜色的单元格是透明的。
启用透明度的输出 |
---|
![]() |
以下示例代码从 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-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Create workbook object from source file | |
Workbook wb = new Workbook(sourceDir + "sampleCreateTransparentImage.xlsx"); | |
// Apply different image or print options | |
var imgOption = new ImageOrPrintOptions(); | |
imgOption.ImageType = Drawing.ImageType.Png; | |
imgOption.HorizontalResolution = 200; | |
imgOption.VerticalResolution = 200; | |
imgOption.OnePagePerSheet = true; | |
// Apply transparency to the output image | |
imgOption.Transparent = true; | |
// Create image after apply image or print options | |
var sr = new SheetRender(wb.Worksheets[0], imgOption); | |
sr.ToImage(0, outputDir + "outputCreateTransparentImage.png"); |