Class SheetRender
Namespace: Aspose.Cells.Rendering
Assembly: Aspose.Cells.dll (25.2.0)
Represents a worksheet render which can render worksheet to various images such as (BMP, PNG, JPEG, TIFF..) The constructor of this class , must be used after modification of pagesetup, cell style.
public class SheetRender
Inheritance
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
SheetRender(Worksheet, ImageOrPrintOptions)
the construct of SheetRender, need worksheet and ImageOrPrintOptions as params
public SheetRender(Worksheet worksheet, ImageOrPrintOptions options)
Parameters
worksheet
Worksheet
Indicate which spreadsheet to be rendered.
options
ImageOrPrintOptions
ImageOrPrintOptions contains some property of output image
Properties
PageCount
Gets the total page count of current worksheet.
public int PageCount { get; }
Property Value
PageScale
Gets calculated page scale of the sheet. Returns the set scale if Aspose.Cells.PageSetup.Zoom is set. Otherwise, returns the calculated scale according to Aspose.Cells.PageSetup.FitToPagesWide and Aspose.Cells.PageSetup.FitToPagesTall.
public double PageScale { get; }
Property Value
Examples
csharp
Workbook wb = new Workbook("Book1.xlsx");
SheetRender sheetRender = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions());
//Gets calculated page scale of the sheet.
double pageScale = sheetRender.PageScale;
Methods
CustomPrint(bool, PrintPageEventArgs)
Client can control page setting of printer when print each page using this function.
public int CustomPrint(bool nextPageAfterPrint, PrintPageEventArgs printPageEventArgs)
Parameters
nextPageAfterPrint
bool
If true , printer will go to next page after print current page
printPageEventArgs
PrintPageEventArgs
System.Drawing.Printing.PrintPageEventArgs
Returns
Indirect next page index, based on zero
Dispose()
Releases resources created and used for rendering.
public void Dispose()
GetPageSizeInch(int)
Get page size in inch of output image.
public float[] GetPageSizeInch(int pageIndex)
Parameters
pageIndex
int
The page index is based on zero.
Returns
float[]
Page size of image, [0] for width and [1] for height
ToImage(int, string)
Render certain page to a file.
public void ToImage(int pageIndex, string fileName)
Parameters
pageIndex
int
indicate which page is to be converted
fileName
string
filename of the output image
Examples
The following code outputs the first page of the first sheet to png image.
csharp
//load the source file with images.
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
//set output image type.
imgOpt.ImageType = ImageType.Png;
//render the first sheet.
SheetRender sr = new SheetRender(wb.Worksheets[0], imgOpt);
//output the first page of the sheet to image.
sr.ToImage(0, "output.png");
ToImage(int, Stream)
Render certain page to a stream.
public void ToImage(int pageIndex, Stream stream)
Parameters
pageIndex
int
indicate which page is to be converted
stream
Stream
the stream of the output image
ToPrinter(string)
Render worksheet to Printer
public void ToPrinter(string printerName)
Parameters
printerName
string
the name of the printer , for example: “Microsoft Office Document Image Writer”
ToPrinter(string, string)
Render worksheet to Printer
public void ToPrinter(string printerName, string jobName)
Parameters
printerName
string
the name of the printer , for example: “Microsoft Office Document Image Writer”
jobName
string
set the print job name
ToPrinter(PrinterSettings)
Render worksheet to Printer
public void ToPrinter(PrinterSettings printerSettings)
Parameters
printerSettings
PrinterSettings
the settings of printer, e.g. PrinterName, Duplex
ToPrinter(PrinterSettings, string)
Render worksheet to Printer
public void ToPrinter(PrinterSettings printerSettings, string jobName)
Parameters
printerSettings
PrinterSettings
the settings of printer, e.g. PrinterName, Duplex
jobName
string
set the print job name
ToPrinter(string, int, int)
Render worksheet to Printer
[Obsolete("Use ToPrinter(string PrinterName) and ImageOrPrintOptions.PageIndex, PageCount instead.")]
public void ToPrinter(string printerName, int printPageIndex, int printPageCount)
Parameters
printerName
string
the name of the printer , for example: “Microsoft Office Document Image Writer”
printPageIndex
int
the 0-based index of the first page to print, it must be in Range [0, SheetRender.PageCount-1]
printPageCount
int
the number of pages to print, it must be greater than zero
Remarks
NOTE: This method is now obsolete. Instead, please use ToPrinter(string PrinterName) and ImageOrPrintOptions.PageIndex, PageCount to set the first page and the number of pages to print. This property will be removed 12 months later since December 2021. Aspose apologizes for any inconvenience you may have experienced.
ToTiff(Stream)
Render whole worksheet as Tiff Image to stream.
public void ToTiff(Stream stream)
Parameters
stream
Stream
the stream of the output image
ToTiff(string)
Render whole worksheet as Tiff Image to a file.
public void ToTiff(string filename)
Parameters
filename
string
the filename of the output image
Examples
The following code outputs all the pages of the first sheet to Tiff image.
csharp
//load the source file with images.
Workbook wb = new Workbook("Book1.xlsx");
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
//set output image type.
imgOpt.SaveFormat = SaveFormat.Tiff;
//render the first sheet.
SheetRender sr = new SheetRender(wb.Worksheets[0], imgOpt);
//output all the pages of the sheet to Tiff image.
sr.ToTiff("output.tiff");