# 不可分割数据

## Content

GcExcel Java 允许用户在导出到PDF文件时将一些行合并到一起不做分割。
此功能非常有用，尤其是当工作表中有大量数据要导出为PDF文件时。例如，假设您有一个表单，其中有多组行经常被隐藏，但最终会在打印时修改页数和分页符。现在，您需要将Excel文件导出为PDF格式，这样它可以将一些行组放合在一起，以便在执行打印操作时不会在分页符或页面之间拆分。在这种情况下，利用此功能在导出到PDF文件时获得完美的打印体验和准确的内容发布是非常有帮助的。

为了使某些行组在分页符上保持在一起，需要首先创建一个单元格区域，其中包含要在PDF文件中一起显示的行。 接下来，创建[PrintManager](/developer/grapecitydocuments/excel-java/api/com/grapecity/documents/excel/PrintManager.html) 类的实例，并使用 [paginate()](/developer/grapecitydocuments/excel-java/api/com/grapecity/documents/excel/PrintManager.html#paginate) 方法确保所需的行一起显示。 完成后，只需使用 [savePageInfosToPDF()](/developer/grapecitydocuments/excel-java/api/com/grapecity/documents/excel/PrintManager.html#savePageInfosToPDF) 方法保存PDF文件。

### 示例代码

请参阅以下示例代码，以允许用户在导出到PDF文件时在分页符上保留一些行。

```Java
// Initialize workbook
Workbook workbook = new Workbook();
        
// Open Excel file
workbook.open("KeepTogether.xlsx");
        
// Fetch default worksheet
IWorksheet worksheet = workbook.getWorksheets().get(0);

/* The first page of the natural pagination is from 
   row 1st to 36th, the second page is from row 37th to 73rd */
List keepTogetherRanges = new ArrayList();

/* The row 37th and 38th need to keep together.
   So the pagination results are: the first page is from row 
   1st to 35th, the second page is from row 36th to 73rd*/
keepTogetherRanges.add(worksheet.getRange("36:37"));

// Create an instance of the PrintManager class
PrintManager printManager = new PrintManager();

// Get the pagination information of the worksheet
List pages = 
printManager.paginate(worksheet, keepTogetherRanges, null);

// Save the modified pages into pdf file
printManager.savePageInfosToPDF("KeepTogether.pdf", pages);
```
