创建 Excel 工作表的透明图像

Contents
[ ]

在下面的工作表图像中,没有应用透明度。没有填充颜色的单元格被绘制成白色。

不透明的输出:单元格背景为白色
待办事项:图片_替代_文本

同时,在下面的工作表图像中,应用了透明度。没有填充颜色的单元格是透明的。

启用透明度的输出
待办事项:图片_替代_文本

以下示例代码从 Excel 工作表生成透明图像。

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