[英]Is there a way to create a split plane horizontally using the Apache POI library in Java? [EXCEL + APACHE POI]
using the createSplitPlane() method in XSSFSheet it is only able to do a 4 pane split.使用 XSSFSheet 中的 createSplitPlane() 方法只能进行 4 窗格拆分。 Is there a way to do a 2 plane split instead horizontally?有没有办法做一个 2 平面拆分而不是水平?
When using Sheet.createSplitPane
one sets following parameters:使用Sheet.createSplitPane
时,设置以下参数:
So if you set xSplitPos
to 0
and leftmostColumn
to 0
, then you should get what you want.因此,如果您将xSplitPos
设置为0
并将leftmostColumn
设置为0
,那么您应该得到您想要的。
But there is a bug with activePane
.但是activePane
有一个错误。
The constant fields in Sheet
are as follows: Sheet
中的常量字段如下:
PANE_LOWER_RIGHT 0
PANE_UPPER_RIGHT 1
PANE_LOWER_LEFT 2
PANE_UPPER_LEFT 3
But the corresponding values in org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane
are:但是org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane
中的对应值是:
INT_BOTTOM_RIGHT 1
INT_TOP_RIGHT 2
INT_BOTTOM_LEFT 3
INT_TOP_LEFT 4
So the first are 0-based while the second are 1-based.所以第一个是基于 0 的,而第二个是基于 1 的。
That's why one needs using +1
to each of the Sheet
constants.这就是为什么需要对每个工作Sheet
常量使用+1
的原因。
Example:例子:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
class CreateExcelSplitPane {
public static void main(String[] args) throws Exception {
try (
Workbook workbook = new XSSFWorkbook(); FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {
//Workbook workbook = new HSSFWorkbook(); FileOutputStream fileout = new FileOutputStream("Excel.xls") ) {
Sheet sheet = workbook.createSheet();
sheet.createSplitPane(0, 100*20, 0, 9, Sheet.PANE_UPPER_LEFT+1);
workbook.write(fileout);
}
}
}
Result:结果:
And when using并且在使用时
...
sheet.createSplitPane(100*20, 0, 3, 0, Sheet.PANE_UPPER_LEFT+1);
...
the result looks like:结果如下:
This is tested and works using apache poi 4.1.1
as well as apache poi 5.2.2
.这是使用apache poi 4.1.1
和apache poi 5.2.2
测试和工作的。
There are additional issues in HSSF
using HSSFSheet.createSplitPane
.使用HSSFSheet.createSplitPane
的HSSF
中还有其他问题。 But that's another question.但这是另一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.