ワークシートをグラフィック コンテキストにレンダリング
Contents
[
Hide
]
Aspose.Cells はワークシートをグラフィック コンテキストにレンダリングできるようになりました。グラフィック コンテキストは、画像ファイル、画面、プリンターなどのようなものです。次の 2 つの方法のいずれかを使用して、ワークシートをグラフィック コンテキストにレンダリングしてください。
次のコードは、Aspose.Cells を使用してワークシートをグラフィック コンテキストにレンダリングする方法を示しています。コードを実行すると、ワークシート全体が印刷され、残りの空きスペースがグラフィック コンテキストの青色で塗りつぶされ、画像が次のように保存されます。**OutputImage_out_.png**ファイル。任意のソース Excel ファイルを使用して、このコードを試すことができます。理解を深めるために、コード内のコメントもお読みください。
This file contains hidden or 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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source file | |
Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create empty Bitmap | |
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1100, 600); | |
// Create Graphics Context | |
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); | |
g.Clear(System.Drawing.Color.Blue); | |
// Set one page per sheet to true in image or print options | |
Aspose.Cells.Rendering.ImageOrPrintOptions opts = new Aspose.Cells.Rendering.ImageOrPrintOptions(); | |
opts.OnePagePerSheet = true; | |
// Render worksheet to graphics context | |
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(worksheet, opts); | |
sr.ToImage(0, g, 0, 0); | |
// Save the graphics context image in Png format | |
bmp.Save(dataDir + "OutputImage_out.png", System.Drawing.Imaging.ImageFormat.Png); |