管理分页符

Aspose.Cells & 分页符

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

工作表由工作表类,它提供了广泛的属性和方法来管理工作表。要添加分页符,请使用工作表班级'水平分页符垂直分页符特性。

水平分页符垂直分页符属性实际上是可能包含多个分页符的集合。每个集合都包含几种用于管理水平和垂直分页符的方法。下面将讨论如何使用这些方法。

添加分页符

要在工作表中添加分页符,请通过调用水平分页符垂直分页符收藏品'添加方法。每个添加方法采用要添加分页符的单元格名称。

// 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");

清除所有分页符

要清除工作表中的所有分页符,请调用HorizontalPageBreakCollectionVerticalPageBreakCollection收藏品'清除方法。

// 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();

删除特定分页符

要删除工作表中的特定分页符,请调用HorizontalPageBreakCollectionVerticalPageBreakCollection收藏品'移除点方法。每个移除点方法将采用要删除的分页符的索引。

// 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);