如何:设置页边距
迪丽瓦拉
2024-03-20 18:56:35
0

如何:指定打印设置

// 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:

PropertyDescription
WorksheetView.Margins定义页边距
WorksheetView.Orientation指定页面方向。
WorksheetView.PaperKind指定纸张大小。
WorksheetView.SetCustomPaperSize指定工作表的自定义纸张大小。

Use the Worksheet.PrintOptions property to configure print options. Print options include the following:

PropertyDescription
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;


自定义纸张尺寸

相关内容