页面设置功能

有时,需要为工作表配置页面设置以控制打印。这些页面设置设置提供了各种选项。

页面选项

待办事项:图片_替代_文本

Aspose.Cells 完全支持页面设置选项。本文介绍如何使用 Aspose.Cells 设置页面选项。

设置页面选项

Aspose.Cells提供了一个类,工作簿,代表一个 Microsoft Excel 文件。 Workbook 类包含一个 Worksheets 集合,允许访问 Excel 文件中的每个工作表。工作表由工作表班级。

Worksheet 类提供了 PageSetup 属性,用于设置页面设置选项。事实上,PageSetup 属性是 PageSetup 类的一个对象,它可以为打印的工作表设置页面布局选项。 PageSetup 类提供了各种用于设置页面设置选项的属性。下面讨论其中一些特性。

页面方向

页面方向可以设置为纵向或横向使用页面设置班级'设置方向(页面方向类型)方法。这设置方向(页面方向类型)方法采用页面方向类型枚举作为参数。的成员页面方向类型列举如下。

页面方向类型 描述
景观 横向
肖像 纵向
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(PageOrientation.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
// Setting the orientation to Portrait
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setOrientation(PageOrientationType.PORTRAIT);
workbook.save(dataDir + "PageOrientation_out.xls");

比例因子

可以通过调整比例因子来缩小或放大工作表的大小设置缩放的方法页面设置班级。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(ScalingFactor.class) + "worksheets/";
// Instantiating a Excel object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
// Setting the scaling factor to 100
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setZoom(100);
workbook.save(dataDir + "ScalingFactor_out.xls");

FitToPages 选项

要使工作表的内容适合特定页数,请使用页面设置班级'setFitToPagesTallsetFitToPagesWide方法。这些方法也用于缩放工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(FitToPagesOptions.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
PageSetup pageSetup = sheet.getPageSetup();
// Setting the number of pages to which the length of the worksheet will be spanned
pageSetup.setFitToPagesTall(1);
// Setting the number of pages to which the width of the worksheet will be spanned
pageSetup.setFitToPagesWide(1);
workbook.save(dataDir + "FitToPagesOptions_out.xls");

纸张尺寸

使用页面设置班级'纸张大小财产。 PaperSize 属性接受纸张大小类型枚举,如下所示。

纸张尺寸类型 描述
纸 10x14 10 英寸 x 14 英寸
纸 11x17 11 英寸 x 17 英寸
试卷A3 A3(297 毫米 x 420 毫米)
纸A4 A4(210 毫米 x 297 毫米)
纸A4小 A4 小(210 毫米 x 297 毫米)
试卷A5 A5(148 毫米 x 210 毫米)
试卷B3 B3(13.9 x 19.7 英寸)
试卷B4 B4(250 毫米 x 354 毫米)
试卷B5 B5(182 毫米 x 257 毫米)
纸质名片 名片(90 毫米 x 55 毫米)
纸片 C尺寸床单
纸D表 D尺寸床单
纸信封10 10 号信封(4-1/8 英寸 x 9-1/2 英寸)
纸信封11 11 号信封(4-1/2 英寸 x 10-3/8 英寸)
纸信封12 12 号信封(4-1/2 英寸 x 11 英寸)
纸信封14 14 号信封(5 英寸 x 11-1/2 英寸)
纸信封9 9 号信封(3-7/8 英寸 x 8-7/8 英寸)
纸质信封B4 信封 B4(250 毫米 x 353 毫米)
纸质信封B5 信封 B5(176 毫米 x 250 毫米)
纸质信封B6 信封 B6(176 毫米 x 125 毫米)
纸质信封C3 信封 C3(324 毫米 x 458 毫米)
纸质信封C4 信封 C4(229 毫米 x 324 毫米)
纸质信封C5 信封 C5(162 毫米 x 229 毫米)
纸质信封C6 信封 C6(114 毫米 x 162 毫米)
纸质信封C65 信封 C65(114 毫米 x 229 毫米)
纸质信封DL 信封 DL(110 毫米 x 220 毫米)
纸信封意大利 意大利信封(110 毫米 x 230 毫米)
纸信封君主 Monarch 信封(3-7/8 英寸 x 7-1/2 英寸)
纸质信封个人 信封(3-5/8 英寸 x 6-1/2 英寸)
纸电子表 E尺寸床单
纸行政 行政(7-1/2 英寸 x 10-1/2 英寸)
PaperFanfoldLegal德语 德国 Legal 对折(8-1/2 英寸 x 13 英寸)
PaperFanfoldStd德语 德国标准对折(8-1/2 英寸 x 12 英寸)
纸质折页美国 美国标准折叠式(14-7/8 英寸 x 11 英寸)
对开纸 对开本(8-1/2 英寸 x 13 英寸)
纸账本 分类帐(17 英寸 x 11 英寸)
纸质法律 合法(8-1/2 英寸 x 14 英寸)
纸信 信纸(8-1/2 英寸 x 11 英寸)
纸信小号 Letter Small(8-1/2 英寸 x 11 英寸)
纸笔记 注(8-1/2 英寸 x 11 英寸)
纸质四开本 四开本(215 毫米 x 275 毫米)
纸质结单 报表(5-1/2 英寸 x 8-1/2 英寸)
纸质小报 小报(11 英寸 x 17 英寸)
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(ManagePaperSize.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
// Setting the paper size to A4
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.PAPER_A_4);
workbook.save(dataDir + "ManagePaperSize_out.xls");

打印质量

设置要打印的工作表的打印质量页面设置班级'设置打印质量方法。打印质量的测量单位是每英寸点数 (DPI)。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetPrintQuality.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
// Setting the print quality of the worksheet to 180 dpi
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPrintQuality(180);
workbook.save(dataDir + "SetPrintQuality_out.xls");

第一页码

使用开始工作表页面编号页面设置班级'设置第一页编号方法。 setFirstPageNumber 方法设置工作表第一页的页码,后面的页面按升序编号。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetFirstPageNumber.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
// Setting the first page number of the worksheet pages
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setFirstPageNumber(2);
workbook.save(dataDir + "SetFirstPageNumber_out.xls");

设置边距

Aspose.Cells 完全支持 Microsoft Excel 的页面设置选项。开发人员可能需要为工作表配置页面设置以控制打印过程。本主题讨论如何使用 Aspose.Cells 配置页边距。

Microsoft Excel 中的页边距

待办事项:图片_替代_文本

Aspose.Cells提供了一个类,工作簿表示 Microsoft Excel 文件。 Workbook 类包含允许访问 Excel 文件中的每个工作表的 Worksheets 集合。工作表由工作表班级。

Worksheet 类提供了 PageSetup 属性,用于设置页面设置选项。 PageSetup 属性是页面设置类,它可以为打印的工作表设置不同的页面布局选项。 PageSetup 类提供了用于设置页面设置选项的各种属性和方法。

页边距

设置页面的页边距(左、右、上、下)页面设置班级成员。下面列出了一些用于指定页边距的方法:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetMargins.class) + "worksheets/";
// Create a workbook object
Workbook workbook = new Workbook();
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.getWorksheets();
// Get the first (default) worksheet
Worksheet worksheet = worksheets.get(0);
// Get the pagesetup object
PageSetup pageSetup = worksheet.getPageSetup();
// Set bottom,left,right and top page margins
pageSetup.setBottomMargin(2);
pageSetup.setLeftMargin(1);
pageSetup.setRightMargin(1);
pageSetup.setTopMargin(3);
workbook.save(dataDir + "SetMargins_out.xls");

页面居中

可以在页面上水平和垂直居中某些内容。这页面设置类有用于此目的的成员:水平居中设置垂直居中.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(CenterOnPage.class) + "worksheets/";
// Create a workbook object
Workbook workbook = new Workbook();
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.getWorksheets();
// Get the first (default) worksheet
Worksheet worksheet = worksheets.get(0);
// Get the pagesetup object
PageSetup pageSetup = worksheet.getPageSetup();
// Set bottom,left,right and top page margins
pageSetup.setCenterHorizontally(true);
pageSetup.setCenterVertically(true);
workbook.save(dataDir + "CenterOnPage_out.xls");

页眉和页脚边距

设置页眉和页脚边距页面设置成员如设置页眉边距设置页脚边距.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(HeaderAndFooterMargins.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Excel file
WorksheetCollection worksheets = workbook.getWorksheets();
int sheetIndex = worksheets.add();
Worksheet sheet = worksheets.get(sheetIndex);
PageSetup pageSetup = sheet.getPageSetup();
// Specify Header / Footer margins
pageSetup.setHeaderMargin(2);
pageSetup.setFooterMargin(2);
workbook.save(dataDir + "HeaderAndFooterMargins_out.xls");

设置页眉和页脚

页眉和页脚是页面上边距上方或底部边距下方的文本和图像部分。也可以向工作表添加页眉和页脚。页眉和页脚可用于显示任何类型的有用信息,例如页码、作者姓名、文档标题或日期和时间。页眉和页脚也可以使用“页面设置”对话框进行管理。

页面设置对话框

待办事项:图片_替代_文本

Aspose.Cells 允许在运行时将页眉和页脚添加到工作表,但建议在预先设计的文件中手动设置页眉和页脚以进行打印。您可以使用 Microsoft Excel 作为 GUI 工具轻松设置页眉和页脚以减少开发时间。 Aspose.Cells 可以导入文件并保留这些设置。

为了在运行时添加页眉和页脚,Aspose.Cells 提供了特殊的类和一些脚本命令来控制格式。

脚本命令

脚本命令是 Aspose.Cells 提供的特殊命令,允许开发人员格式化页眉和页脚。

脚本命令 描述
&P 当前页码。
&G 照片。
&N 总页数。
&D 当前日期。
&T 当前时间。
&一种 工作表的名称。
&F 没有路径的文件名。
&"<FontName>" 字体名称。例如:&“宋体”
&"<FontName>, <FontStyle>" 带有样式的字体名称。例如:&“Arial,Bold”
&<FontSize> 表示字体大小。例如:“&14abc”。但是,如果此命令后跟要在标题中打印的普通数字,则应使用空格字符将其与字体大小分隔开。例如:“&14 123”。

设置页眉和页脚

页面设置类提供方法[设置标题](https://reference.aspose.com/cells/java/com.aspose.cells/pagesetup#setHeader(int,%20java.lang.String) 用于添加标题和[设置页脚](https://reference.aspose.com/cells/java/com.aspose.cells/pagesetup#setFooter(int,%20java.lang.String)用于向工作表添加页脚。该脚本用作上述所有方法的参数。它表示用于页眉或页脚的脚本。此脚本包含用于格式化页眉或页脚的脚本命令。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetHeadersAndFooters.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = workbook.getWorksheets().get(0).getPageSetup();
// Setting worksheet name at the left header
pageSetup.setHeader(0, "&A");
// Setting current date and current time at the central header and changing the font of the header
pageSetup.setHeader(1, "&\"Times New Roman,Bold\"&D-&T");
// Setting current file name at the right header and changing the font of the header
pageSetup.setHeader(2, "&\"Times New Roman,Bold\"&12&F");
// Setting a string at the left footer and changing the font of the footer
pageSetup.setFooter(0, "Hello World! &\"Courier New\"&14 123");
// Setting picture at the central footer
pageSetup.setFooter(1, "&G");
FileInputStream fis = new FileInputStream(dataDir + "footer.jpg");
byte[] picData = new byte[fis.available()];
fis.read(picData);
pageSetup.setFooterPicture(1, picData);
fis.close();
// Setting the current page number and page count at the right footer
pageSetup.setFooter(2, "&Pof&N");
workbook.save(dataDir + "SetHeadersAndFooters_out.xls");

将图形插入页眉或页脚

页面设置类有方法[设置头像](https://reference.aspose.com/cells/java/com.aspose.cells/pagesetup#setHeaderPicture(int,%20byte[]) ) 和[设置页脚图片](https://reference.aspose.com/cells/java/com.aspose.cells/pagesetup#setFooterPicture(int,%20byte[])用于将图片添加到工作表的页眉和页脚。这些方法有两个参数:

  • 部分,将放置图片的页眉或页脚部分。分为左、中、右三部分,分别用数值0、1、2表示。
  • 文件输入流图形数据。二进制数据应写入字节数组的缓冲区。

执行代码并打开文件后,在 Microsoft Excel 中检查工作表的标题:

  1. 文件菜单,选择页面设置.
  2. 在“页面设置”对话框中,选择页眉页脚标签。

在页眉/页脚中插入图形

待办事项:图片_替代_文本

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(InsertImageInHeaderFooter.class) + "worksheets/";
// Creating a Workbook object
Workbook workbook = new Workbook();
// Creating a string variable to store the url of the logo/picture
String logo_url = dataDir + "school.jpg";
// Creating the instance of the FileInputStream object to open the logo/picture in the stream
FileInputStream inFile = new FileInputStream(logo_url);
// Creating a PageSetup object to get the page settings of the first worksheet of the workbook
PageSetup pageSetup = workbook.getWorksheets().get(0).getPageSetup();
// Setting the logo/picture in the central section of the page header
pageSetup.setHeader(1, "&G");
byte[] picData = new byte[inFile.available()];
inFile.read(picData);
pageSetup.setHeaderPicture(1, picData);
// Setting the Sheet's name in the right section of the page header with the script
pageSetup.setHeader(2, "&A");
// Saving the workbook
workbook.save(dataDir + "InsertImageInHeaderFooter_out.xls");
// Closing the FileStream object
inFile.close();

仅在首页页眉中插入图形

页面设置类还有其他有用的方法,例如设置图片, 设置第一页页眉, 设置第一页页脚, 用于将图片添加到工作表的第一页页眉/页脚中。第一页是一个特殊页面:通常希望它显示特殊信息,例如公司标志。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(InsertGraphicinFirstPageHeaderOnly.class) + "worksheets/";
// Creating a Workbook object
Workbook workbook = new Workbook();
// Get the first worksheet (default).
Worksheet worksheet = workbook.getWorksheets().get(0);
// Adding some sample value to cells
Cells cells = worksheet.getCells();
Cell cell = cells.get("A1");
cell.setValue("Page1");
cell = cells.get("A60");
cell.setValue("Page2");
cell = cells.get("A113");
cell.setValue("Page3");
// Creating a PageSetup object to get the page settings of the first
// worksheet of the workbook
PageSetup pageSetup = worksheet.getPageSetup();
// Creating a string variable to store the url of the logo/picture
String logo_url = dataDir + "school.jpg";
// Creating the instance of the FileInputStream object to open the logo/picture in the stream
FileInputStream inFile = new FileInputStream(logo_url);
byte[] picData = new byte[inFile.available()];
inFile.read(picData);
// Setting the logo/picture in the right section of the first page header only
pageSetup.setHFDiffFirst(true);
pageSetup.setFirstPageHeader(2, "&G");
pageSetup.setPicture(true, false, true, 2, picData);
// Saving the workbook
workbook.save(dataDir + "IGInFirstPageHeaderOnly_out.xlsx");
// Closing the FileStream object
inFile.close();

设置打印选项

Microsoft Excel 的页面设置设置提供了多个打印选项(也称为工作表选项),允许用户控制工作表页面的打印方式。这些打印选项允许用户:

  • 选择工作表上的特定打印区域。
  • 打印标题。
  • 打印网格线。
  • 打印行和列标题
  • 达到草稿质量。
  • 打印评论。
  • 打印单元错误。
  • 定义页面排序。

所有这些打印选项如下所示。

打印(纸张)选项

待办事项:图片_替代_文本

设置打印和工作表选项

spose.Cells 支持 Microsoft Excel 提供的所有打印选项,开发人员可以使用提供的属性轻松地为工作表配置这些选项页面设置班级。下面将更详细地讨论如何使用这些属性。

设置打印区域

默认情况下,只有打印区域包含工作表中包含数据的所有区域。开发人员可以建立工作表的特定打印区域。

要选择特定的打印区域,请使用页面设置班级'设置打印区域财产。将定义打印区域的单元格范围分配给此属性。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetPrintArea.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Workbook file
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
// Specifying the cells range (from A1 cell to T35 cell) of the print area
pageSetup.setPrintArea("A1:T35");
workbook.save(dataDir + "SetPrintArea_out.xls");

设置打印标题

Aspose.Cells 允许您指定行和列标题以在打印的工作表的所有页面上重复。为此,请使用页面设置班级'setPrintTitleColumns设置打印标题行特性。

将重复的行或列通过传递它们的行号或列号来定义。例如,行定义为 $1:$2,列定义为 $A:$B。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetPrintTitle.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Workbook file
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
// Defining column numbers A & B as title columns
pageSetup.setPrintTitleColumns("$A:$B");
// Defining row numbers 1 & 2 as title rows
pageSetup.setPrintTitleRows("$1:$2");
// Save the workbook.
workbook.save(dataDir + "SetPrintTitle_out.xls");

设置其他打印选项

页面设置类还提供了几个其他属性来设置常规打印选项,如下所示:

设置打印评论打印错误属性,Aspose.Cells还提供了两个枚举,打印注释类型打印错误类型包含要分配给的预定义值设置打印注释设置打印错误分别属性。

中的预定义值打印注释类型枚举描述如下。

打印注释类型 描述
打印位置 指定打印工作表上显示的注释。
打印_NO_COMMENTS 指定不打印注释。
PRINT_SHEET_END 指定在工作表末尾打印注释。

的预定义值打印错误类型枚举描述如下。

打印错误类型 描述
打印_错误_空白 指定不打印错误。
打印错误破折号 指定将错误打印为“–”。
打印错误显示 指定打印显示的错误。
PRINT_ERRORS_NA 指定将错误打印为“#N/A”。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(OtherPrintOptions.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Workbook file
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
// Allowing to print gridlines
pageSetup.setPrintGridlines(true);
// Allowing to print row/column headings
pageSetup.setPrintHeadings(true);
// Allowing to print worksheet in black & white mode
pageSetup.setBlackAndWhite(true);
// Allowing to print comments as displayed on worksheet
pageSetup.setPrintComments(PrintCommentsType.PRINT_IN_PLACE);
// Allowing to print worksheet with draft quality
pageSetup.setPrintDraft(true);
// Allowing to print cell errors as N/A
pageSetup.setPrintErrors(PrintErrorsType.PRINT_ERRORS_NA);
workbook.save(dataDir + "OtherPrintOptions_out.xls");

设置页面顺序

页面设置类提供了设置顺序用于订购要打印的工作表的多页的属性。页面排序有两种可能性,如下所示:

  • 下来然后结束在向右打印任何页面之前先向下打印所有页面。
  • 过来然后下来在打印下面的任何页面之前先从左到右打印页面。

Aspose.Cells 提供枚举,打印订单类型,其中包含要分配给的所有预定义订单类型设置顺序方法。

的预定义值打印订单类型枚举描述如下。

打印订单类型 描述
DOWN_THEN_OVER 打印下来,然后结束。
OVER_THEN_DOWN 打印过来,然后向下。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String dataDir = Utils.getSharedDataDir(SetPageOrder.class) + "worksheets/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Accessing the first worksheet in the Workbook file
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Obtaining the reference of the PageSetup of the worksheet
PageSetup pageSetup = sheet.getPageSetup();
// Setting the printing order of the pages to over then down
pageSetup.setOrder(PrintOrderType.OVER_THEN_DOWN);
workbook.save(dataDir + "SetPageOrder_out.xls");

删除 Excel 文件中工作表的现有打印机设置

请参阅与此主题相关的这篇文章。

推进主题