// Set page orientation to landscape.
worksheet.ActiveView.Orientation = PageOrientation.Landscape;
// Select paper size.
worksheet.ActiveView.PaperKind = System.Drawing.Printing.PaperKind.A4;
// Access an object that contains print options.
WorksheetPrintOptions printOptions = worksheet.PrintOptions;
// Do not print gridlines.
printOptions.PrintGridlines = false;
// Scale the worksheet to fit within the width of one page.
printOptions.FitToPage = true;
printOptions.FitToWidth = 1;
// Print in black and white.
printOptions.BlackAndWhite = true;
// Print a dash instead of a cell error message.
printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash;
// Define a print area on a worksheet.
CellRange printArea = worksheet["B1:F39"];
worksheet.SetPrintRange(printArea);// Enlarge the print area by adding adjacent cells.
// An additional print area is created if you add non-adjacent cells to the print area.
worksheet.AddPrintRange(worksheet["B40:F50"]);// Uncomment the following line to clear the print area and print the entire worksheet.
// worksheet.ClearPrintRange();
如何:在工作表中插入分页符
// Insert a page break after the "F" column.
worksheet.VerticalPageBreaks.Add(6);
// Insert a page break below the 14th row.
worksheet.HorizontalPageBreaks.Add(14);
Use the Worksheet.ActiveView property to specify the following page options:
Property | Description |
---|---|
WorksheetView.Margins | 定义页边距 |
WorksheetView.Orientation | 指定页面方向。 |
WorksheetView.PaperKind | 指定纸张大小。 |
WorksheetView.SetCustomPaperSize | 指定工作表的自定义纸张大小。 |
Use the Worksheet.PrintOptions property to configure print options. Print options include the following:
Property | Description |
---|---|
WorksheetPrintOptions.FitToPage | 指示是否缩放工作表以使其数据适合指定页数。 |
WorksheetPrintOptions.FitToWidth | 指定工作表应水平容纳的页数。 |
WorksheetPrintOptions.FitToHeight | 指定工作表在垂直方向上应容纳的页数。 |
WorksheetPrintOptions.Scale | 指定缩放工作表内容的百分比。 |
WorksheetPrintOptions.PrintGridlines | 指定是否打印工作表网格线。 |
WorksheetPrintOptions.PrintHeadings | 指定是否打印行标题和列标题。 |
WorksheetPrintOptions.PrintTitles | 允许您在打印页面上重复特定的行和列。 |
WorksheetPrintOptions.BlackAndWhite | 允许您以黑白方式打印工作表。 |
WorksheetPrintOptions.PageOrder | 指定打印页面的顺序。 |
WorksheetPrintOptions.PageNumbering | 允许您指定第一页码。 |
WorksheetPrintOptions.CenterHorizontally | 指定是否在打印页面上水平居中数据。 |
WorksheetPrintOptions.CenterVertically | 指定是否在打印页面上垂直居中数据。 |
WorksheetPrintOptions.ErrorsPrintMode | 指定如何打印单元格错误。 |
如何:设置页边距
// Set the page orientation to Landscape.
workbook.Worksheets[0].ActiveView.Orientation = PageOrientation.Landscape;