为 XSSFSheet 设置顶行和左列 [英] Set top row and left column for an XSSFSheet

查看:59
本文介绍了为 XSSFSheet 设置顶行和左列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确保文件打开时 XLSX 表位于左上角.

XSSFSheet 有一个 getTopCol()getLeftCol() 方法,但没有 setter.

XSSFSheet.showInPane(int, int) 确实有效,但前提是窗格被冻结或拆分.

 PaneInformation pane = sheet.getPaneInformation();如果(窗格==空){//当没有窗格时 FIXME 不起作用sheet.showInPane(CellAddress.A1.getRow(), CellAddress.A1.getColumn());} 别的 {//好的sheet.showInPane(pane.getHorizo​​ntalSplitPosition(),pane.getVerticalSplitPosition());}

我试图查看可以从 XSSFSheet 类访问的内容,但所有底层方法都是私有的.

有人知道将工作表的视图重置到左上角单元格的方法吗?

解决方案

似乎没有直接与 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

<预><代码>...((XSSFSheet)sheet).getCTWorksheet().getSheetViews().getSheetViewArray(0).setTopLeftCell("D10");...

获得此类信息的最佳方法是直接使用 Excel 创建一个简单的文件.然后将其保存为 *.xlsx.然后解压这个文件并查看/xl/worksheets/sheet1.xml.在那里你会发现:

<预><代码>...<工作表视图><sheetView workbookViewId="0" tabSelected="true" topLeftCell="D10"/></sheetViews>...

I am trying to make sure an XLSX sheet is at the top left when the file is open.

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

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?

解决方案

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

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 设置顶行和左列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆