问题描述
我正在尝试开发一个复杂的报告,我需要为 excel 文件设置打印区域.我必须将 xls 文件分成 3 部分,但是如果我执行 setPrintArea(..) 新区域订阅旧区域,结果是我在打印预览中只有最后一页.如何设置多个打印区域?这是代码:
I'm trying to develop a complex report, and I need to set up the print areas for the excel file. I must divide the xls file in 3 part, but if I do setPrintArea(..) the new area subscribe the old and the result is that I have in the print preview only the last page. How can I set more than one print area? This is the code:
protected void createCustomerSheet(String label) {
createSheet(label);
getCurrentSheet().getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE);
getCurrentSheet().getPrintSetup().setFitHeight((short)1);
getCurrentSheet().getPrintSetup().setFitWidth((short)1);
getCurrentSheet().setAutobreaks(true);
getCurrentSheet().setFitToPage(true);
}
然后我打了3次电话
wb.setPrintArea(activeSheetIndex, startColumn, endColumn, startRow, endRow);
我也尝试添加中断行,但它不起作用..
I also tried to add break rows, but it doesn't work..
有什么想法吗?
推荐答案
Excel 只维护一个 打印区域 用于电子表格.所以Apache POI的Excel API提供了设置一个打印区域的能力.
Excel maintains only one print area for a spreadsheet. So Apache POI's Excel API provides the ability to set one print area.
听起来您可能正在尝试定义报告的不同页面.如果是这样,您需要在要完成此操作的每个工作表中设置行和/或列分隔符.使用Sheet的以下方法,假设sheet
是你的 Sheet
实例:
It sounds like you might be trying to define different pages of a report. If so, you'll need to set row and/or column breaks in each Sheet in which you want this done. Use the following methods of Sheet, assuming sheet
is your Sheet
instance:
sheet.setAutobreaks(false);
sheet.setRowBreak(rowIndex);
sheet.setColumnBreak(columnIndex);
您可以多次调用最后两个方法中的每一个以建立多个中断.
You may call each of those last 2 methods multiple times to establish multiple breaks.
这篇关于Apache poi - 打印布局,在同一张纸上有多个打印区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!