问题描述
我正在尝试确保打开文件时XLSX工作表位于左上方.
I am trying to make sure an XLSX sheet is at the top left when the file is open.
XSSFSheet
具有 getTopCol()
和 getLeftCol()
方法,但没有设置方法.
The XSSFSheet
has a getTopCol()
and a getLeftCol()
methods, but there is no setter.
XSSFSheet.showInPane(int, int)
does work, but only if pane is frozen or split.
PaneInformation pane = sheet.getPaneInformation();
if (pane == null) {
// FIXME doesn't work when there is no pane
sheet.showInPane(CellAddress.A1.getRow(), CellAddress.A1.getColumn());
} else {
// OK
sheet.showInPane(pane.getHorizontalSplitPosition(), pane.getVerticalSplitPosition());
}
我试图查看可以从XSSFSheet类访问的内容,但是所有基础方法都是私有的.
I tried to view what could be accessed from the XSSFSheet class, but all underlying methods are private.
有人知道将图纸视图重设为左上角单元格的方法吗?
Does anybody know of a way to reset the view of a sheet to the top left cell?
推荐答案
似乎没有直接通过POI
对象进行的设置.但是CTWorksheet
是可能的. http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/ooxml-schemas/1.1/org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorksheet.java#CTWorksheet
Seems as if there is not such setting directly with the POI
objects. But it is possible with CTWorksheet
. http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/ooxml-schemas/1.1/org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorksheet.java#CTWorksheet
...
((XSSFSheet)sheet).getCTWorksheet().getSheetViews().getSheetViewArray(0).setTopLeftCell("D10");
...
获得此类信息的最佳可能性是直接使用Excel
创建一个简单文件.然后将其另存为*.xlsx
.然后解压缩该文件,然后在/xl/worksheets/sheet1.xml
中查找.在那里您找到:
Best possibility getting such informations is creating a simple file directly with Excel
. Then save this as *.xlsx
. Then unzip this file and look in /xl/worksheets/sheet1.xml
. There you find:
...
<sheetViews>
<sheetView workbookViewId="0" tabSelected="true" topLeftCell="D10"/>
</sheetViews>
...
这篇关于设置XSSFSheet的顶行和左列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!