管理分页符
Contents
[
Hide
]
分页符是文本中一页结束和下一页开始的地方。 Microsoft Excel 可以在工作表中的任何选定单元格处添加分页符。 页面在添加分页符的单元格结束,分页符后的所有数据打印在下一页上。简而言之,分页符将工作表分成多个页面。也可以使用 Aspose.Cells 在运行时向工作表添加分页符。Aspose.Cells 支持两种分页符:
- 水平的
- 垂直的。
本文介绍如何使用 Aspose.Cells 在工作表中添加水平或垂直分页符。
Aspose.Cells & 分页符
Aspose.Cells提供了一个类,工作簿表示一个 Excel 文件。这工作簿类包含一个工作表集合允许访问 Excel 文件中的每个工作表。
工作表由工作表类,它提供了广泛的属性和方法来管理工作表。要添加分页符,请使用工作表班级'水平分页符和垂直分页符特性。
这水平分页符和垂直分页符属性实际上是可能包含多个分页符的集合。每个集合都包含几种用于管理水平和垂直分页符的方法。下面将讨论如何使用这些方法。
添加分页符
要在工作表中添加分页符,请通过调用水平分页符和垂直分页符收藏品'添加方法。每个添加方法采用要添加分页符的单元格名称。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getSharedDataDir(AddingPageBreaks.class) + "worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Add a page break at cell Y30 | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
HorizontalPageBreakCollection hPageBreaks = worksheet.getHorizontalPageBreaks(); | |
hPageBreaks.add("Y30"); | |
VerticalPageBreakCollection vPageBreaks = worksheet.getVerticalPageBreaks(); | |
vPageBreaks.add("Y30"); |
在分页预览或打印预览模式下,您可以看到这些分页是如何工作的。
清除所有分页符
要清除工作表中的所有分页符,请调用HorizontalPageBreakCollection和VerticalPageBreakCollection收藏品'清除方法。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getSharedDataDir(AddingPageBreaks.class) + "worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
workbook.getWorksheets().get(0).getHorizontalPageBreaks().clear(); | |
workbook.getWorksheets().get(0).getVerticalPageBreaks().clear(); |
删除特定分页符
要删除工作表中的特定分页符,请调用HorizontalPageBreakCollection和VerticalPageBreakCollection收藏品'移除点方法。每个移除点方法将采用要删除的分页符的索引。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
String dataDir = Utils.getSharedDataDir(RemoveSpecificPageBreak.class) + "worksheets/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "SampleXLSFile_38kb.xls"); | |
// Removing a specific page break | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet worksheet = worksheets.get(0); | |
HorizontalPageBreakCollection hPageBreaks = worksheet.getHorizontalPageBreaks(); | |
hPageBreaks.removeAt(0); | |
VerticalPageBreakCollection vPageBreaks = worksheet.getVerticalPageBreaks(); | |
vPageBreaks.removeAt(0); |