Class PageSetup
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Encapsulates the object that represents the page setup description. The PageSetup object contains all page setup options.
public class PageSetup
Inheritance
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
Workbook workbook = new Workbook();
WorksheetCollection sheets = workbook.Worksheets;
//Add a worksheet
sheets.Add();
Worksheet sheet = sheets[1];
PageSetup pageSetup = sheet.PageSetup;
pageSetup.PrintArea = "D1:K13";
//do your business
Dim excel as Workbook = new Workbook()
Dim sheets as WorksheetCollection = excel.Worksheets
'Add a worksheet
sheets.Add()
Dim sheet as Worksheet = sheets(1)
Dim pageSetup as PageSetup = sheet.PageSetup
pageSetup.PrintArea = "D1:K13"
Properties
BlackAndWhite
Represents if elements of the document will be printed in black and white.
public bool BlackAndWhite { get; set; }
Property Value
BottomMargin
Represents the size of the bottom margin, in unit of centimeters.
public double BottomMargin { get; set; }
Property Value
BottomMarginInch
Represents the size of the bottom margin, in unit of inches.
public double BottomMarginInch { get; set; }
Property Value
CenterHorizontally
Represent if the sheet is printed centered horizontally.
public bool CenterHorizontally { get; set; }
Property Value
CenterVertically
Represent if the sheet is printed centered vertically.
public bool CenterVertically { get; set; }
Property Value
FirstPageNumber
Represents the first page number that will be used when this sheet is printed.
public int FirstPageNumber { get; set; }
Property Value
FitToPagesTall
Represents the number of pages tall the worksheet will be scaled to when it’s printed. The default value is 1.
public int FitToPagesTall { get; set; }
Property Value
Remarks
You have to set FitToPagesWide as zero if you want to fit all rows on one page.
FitToPagesWide
Represents the number of pages wide the worksheet will be scaled to when it’s printed. The default value is 1.
public int FitToPagesWide { get; set; }
Property Value
Remarks
You have to set FitToPagesTall as zero if you want to fit all columns on one page.
FooterMargin
Represents the distance from the bottom of the page to the footer, in unit of centimeters.
public double FooterMargin { get; set; }
Property Value
FooterMarginInch
Represents the distance from the bottom of the page to the footer, in unit of inches.
public double FooterMarginInch { get; set; }
Property Value
HeaderMargin
Represents the distance from the top of the page to the header, in unit of centimeters.
public double HeaderMargin { get; set; }
Property Value
HeaderMarginInch
Represents the distance from the top of the page to the header, in unit of inches.
public double HeaderMarginInch { get; set; }
Property Value
IsAutoFirstPageNumber
Indicates whether the first the page number is automatically assigned.
public bool IsAutoFirstPageNumber { get; set; }
Property Value
IsAutomaticPaperSize
Indicates whether the paper size is automatic.
public bool IsAutomaticPaperSize { get; }
Property Value
IsHFAlignMargins
Indicates whether header and footer margins are aligned with the page margins. If this property is true, the left header and footer will be aligned with the left margin, and the right header and footer will be aligned with the right margin. This option is enabled by default.
public bool IsHFAlignMargins { get; set; }
Property Value
IsHFDiffFirst
True means that the header/footer of the first page is different with other pages.
public bool IsHFDiffFirst { get; set; }
Property Value
IsHFDiffOddEven
True means that the header/footer of the odd pages is different with odd pages.
public bool IsHFDiffOddEven { get; set; }
Property Value
IsHFScaleWithDoc
Indicates whether header and footer are scaled with document scaling. Only applies for Excel 2007.
public bool IsHFScaleWithDoc { get; set; }
Property Value
IsPercentScale
If this property is False, the FitToPagesWide and FitToPagesTall properties control how the worksheet is scaled.
public bool IsPercentScale { get; set; }
Property Value
LeftMargin
Represents the size of the left margin, in unit of centimeters.
public double LeftMargin { get; set; }
Property Value
LeftMarginInch
Represents the size of the left margin, in unit of inches.
public double LeftMarginInch { get; set; }
Property Value
ODSPageBackground
Gets the background of ODS.
public OdsPageBackground ODSPageBackground { get; }
Property Value
Order
Represents the order that Microsoft Excel uses to number pages when printing a large worksheet.
public PrintOrderType Order { get; set; }
Property Value
Orientation
Represents page print orientation.
public PageOrientationType Orientation { get; set; }
Property Value
PaperHeight
Gets the height of the paper in unit of inches , considered page orientation.
public double PaperHeight { get; }
Property Value
PaperSize
Represents the size of the paper.
public PaperSizeType PaperSize { get; set; }
Property Value
PaperWidth
Gets the width of the paper in unit of inches, considered page orientation.
public double PaperWidth { get; }
Property Value
PrintArea
Represents the range to be printed.
public string PrintArea { get; set; }
Property Value
PrintComments
Represents the way comments are printed with the sheet.
public PrintCommentsType PrintComments { get; set; }
Property Value
PrintCopies
Get and sets number of copies to print.
public int PrintCopies { get; set; }
Property Value
PrintDraft
Represents if the sheet will be printed without graphics.
public bool PrintDraft { get; set; }
Property Value
PrintErrors
Specifies the type of print error displayed.
public PrintErrorsType PrintErrors { get; set; }
Property Value
PrintGridlines
Represents if cell gridlines are printed on the page.
public bool PrintGridlines { get; set; }
Property Value
PrintHeadings
Represents if row and column headings are printed with this page.
public bool PrintHeadings { get; set; }
Property Value
PrintQuality
Represents the print quality.
public int PrintQuality { get; set; }
Property Value
PrintTitleColumns
Represents the columns that contain the cells to be repeated on the left side of each page.
public string PrintTitleColumns { get; set; }
Property Value
Examples
csharp
[C#]
pageSetup.PrintTitleColumns = "$A:$A";
[Visula Basic]
pageSetup.PrintTitleColumns = "$A:$A"
PrintTitleRows
Represents the rows that contain the cells to be repeated at the top of each page.
public string PrintTitleRows { get; set; }
Property Value
Examples
csharp
[C#]
pageSetup.PrintTitleRows = "$1:$1";
[Visula Basic]
pageSetup.PrintTitleRows = "$1:$1"
PrinterSettings
Gets and sets the settings of the default printer.
public byte[] PrinterSettings { get; set; }
Property Value
byte[]
RightMargin
Represents the size of the right margin, in unit of centimeters.
public double RightMargin { get; set; }
Property Value
RightMarginInch
Represents the size of the right margin, in unit of inches.
public double RightMarginInch { get; set; }
Property Value
TopMargin
Represents the size of the top margin, in unit of centimeters.
public double TopMargin { get; set; }
Property Value
TopMarginInch
Represents the size of the top margin, in unit of inches.
public double TopMarginInch { get; set; }
Property Value
Zoom
Represents the scaling factor in percent. It should be between 10 and 400.
public int Zoom { get; set; }
Property Value
Methods
ClearHeaderFooter()
Clears header and footer setting.
public void ClearHeaderFooter()
Copy(PageSetup, CopyOptions)
Copies the setting of the page setup.
public void Copy(PageSetup source, CopyOptions copyOptions)
Parameters
source
PageSetup
The source.
copyOptions
CopyOptions
The copy options.
CustomPaperSize(double, double)
Sets the custom paper size, in unit of inches.
public void CustomPaperSize(double width, double height)
Parameters
width
double
The width of the paper.
height
double
The height of the paper.
GetCommands(string)
Gets all commands of header or footer.
public HeaderFooterCommand[] GetCommands(string headerFooterScript)
Parameters
headerFooterScript
string
The header/footer script
Returns
Returns all commands of header or footer.
GetEvenFooter(int)
Gets a script formatting the even footer of an Excel file.
public string GetEvenFooter(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetEvenHeader(int)
Gets a script formatting the even header of an Excel file.
public string GetEvenHeader(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetFirstPageFooter(int)
Gets a script formatting the first page footer of an Excel file.
public string GetFirstPageFooter(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetFirstPageHeader(int)
Gets a script formatting the first page header of an Excel file.
public string GetFirstPageHeader(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetFooter(int)
Gets a script formatting the footer of an Excel file.
public string GetFooter(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetHeader(int)
Gets a script formatting the header of an Excel file.
public string GetHeader(int section)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
GetPicture(bool, int)
Gets the Aspose.Cells.Drawing.Picture object of the header / footer.
public Picture GetPicture(bool isHeader, int section)
Parameters
isHeader
bool
Indicates whether it is in the header or footer.
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
Returns Aspose.Cells.Drawing.Picture object. Returns null if there is no picture.
GetPicture(bool, bool, bool, int)
Gets the Aspose.Cells.Drawing.Picture object of the header / footer.
public Picture GetPicture(bool isFirst, bool isEven, bool isHeader, int section)
Parameters
isFirst
bool
Indicates whether getting the picture of first page header/footer.
isEven
bool
Indicates whether getting the picture of even page header/footer.
isHeader
bool
Indicates whether getting the picture of header/footer.
section
int
0: Left Section, 1: Center Section, 2: Right Section.
Returns
Returns Aspose.Cells.Drawing.Picture object.
SetEvenFooter(int, string)
Sets a script formatting the even page footer of an Excel file. Only effect in Excel 2007 when IsHFDiffOddEven is true.
public void SetEvenFooter(int section, string footerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
footerScript
string
Footer format script.
SetEvenHeader(int, string)
Sets a script formatting the even page header of an Excel file. Only effect in Excel 2007 when IsHFDiffOddEven is true.
public void SetEvenHeader(int section, string headerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
headerScript
string
Header format script.
SetFirstPageFooter(int, string)
Sets a script formatting the first page footer of an Excel file.
public void SetFirstPageFooter(int section, string footerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
footerScript
string
Footer format script.
SetFirstPageHeader(int, string)
Sets a script formatting the first page header of an Excel file. Only effect in Excel 2007 when IsHFDiffFirst is true.
public void SetFirstPageHeader(int section, string headerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
headerScript
string
Header format script.
SetFitToPages(int, int)
Sets the number of pages the worksheet will be scaled to when it’s printed.
public void SetFitToPages(int wide, int tall)
Parameters
wide
int
Pages wide.
tall
int
Pages tall.
SetFooter(int, string)
Sets a script formatting the footer of an Excel file.
public void SetFooter(int section, string footerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
footerScript
string
Footer format script.
Remarks
Script commands:
Command | Description |
---|---|
&P | Current page number |
&N | Page count |
&D | Current date |
&T | Current time |
&A | Sheet name |
&F | File name without path |
&"<FontName>" | Font name, for example: &"Arial" |
&"<FontName>, <FontStyle>" | Font name and font style, for example: &"Arial,Bold" |
&<FontSize> | Font size. If this command is followed by a plain number to be printed in the header, it will be separated from the font height with a space character. |
&K<RRGGBB> | Font color, for example(RED): &KFF0000 |
&G | Image script |
SetFooterPicture(int, byte[])
Sets an image in the footer of a worksheet.
public Picture SetFooterPicture(int section, byte[] footerPicture)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
footerPicture
byte[]
Image data.
Returns
Returns Aspose.Cells.Drawing.Picture object.
SetHeader(int, string)
Sets a script formatting the header of an Excel file.
public void SetHeader(int section, string headerScript)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
headerScript
string
Header format script.
Remarks
Script commands:
Command | Description |
---|---|
&P | Current page number |
&N | Page count |
&D | Current date |
&T | Current time |
&A | Sheet name |
&F | File name without path |
&"<FontName>" | Font name, for example: &"Arial" |
&"<FontName>, <FontStyle>" | Font name and font style, for example: &"Arial,Bold" |
&<FontSize> | Font size. If this command is followed by a plain number to be printed in the header, it will be separated from the font height with a space character. |
&K<RRGGBB> | Font color, for example(RED): &KFF0000 |
&G | Image script |
SetHeaderPicture(int, byte[])
Sets an image in the header of a worksheet.
public Picture SetHeaderPicture(int section, byte[] headerPicture)
Parameters
section
int
0: Left Section, 1: Center Section, 2: Right Section.
headerPicture
byte[]
Image data.
Returns
Returns Aspose.Cells.Drawing.Picture object.
SetPicture(bool, bool, bool, int, byte[])
Sets an image in the header/footer of a worksheet.
public Picture SetPicture(bool isFirst, bool isEven, bool isHeader, int section, byte[] imageData)
Parameters
isFirst
bool
Indicates whether setting the picture of first page header/footer.
isEven
bool
Indicates whether setting the picture of even page header/footer.
isHeader
bool
Indicates whether setting the picture of header/footer.
section
int
0: Left Section, 1: Center Section, 2: Right Section.
imageData
byte[]
Image data.
Returns
Returns Aspose.Cells.Drawing.Picture object.