Excelワークシートの透過画像を作成
Contents
[
Hide
]
場合によっては、ワークシートの画像を透明な画像として生成する必要があります。塗りつぶしの色がないすべてのセルに透明度を適用します。 Aspose.Cells はImageOrPrintOptions.Transparentワークシート イメージに透明度を適用するプロパティ。このプロパティが間違いの場合、塗りつぶしの色のないセルは白色で描画されます。真実、塗りつぶしの色のないセルは透明に描画されます。
次のワークシート イメージでは、透明度が適用されていません。塗りつぶしの色がないセルは白で描画されます。
透明度なしの出力: セルの背景は白です |
---|
![]() |
一方、次のワークシート イメージでは、透明度が適用されています。塗りつぶしの色がないセルは透明です。
透明度を有効にして出力 |
---|
![]() |
次のサンプル コードは、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"); |