使用apache poi在excel文件中设置页面查看模式 [英] Set page view mode in excel file using apache poi

查看:54
本文介绍了使用apache poi在excel文件中设置页面查看模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel 有不同的查看工作表的模式:正常、页面布局、分页预览.(在 excel 2010 中:在视图选项卡中).工作簿中每个工作表的视图模式都单独保存,再次打开时会恢复.

Excel has different modes for viewing a sheet: Normal, Page Layout, Page Break Preview. (In excel 2010: in the view tab). The view mode is saved seperately for each sheet in a workbook and is restored when opened again.

我正在尝试找到一种使用 HSSF 或 XSSF 设置视图模式的方法.不幸的是,在旧的二进制格式中,找到答案似乎是不可能的.在 2007+ OOXML format diffing 确实给出了基本答案,查看 xl/worksheets/sheet1.xml在普通视图中:

I am trying to find a way to set a view mode using Either HSSF or XSSF. In the old binary format, finding the answer seems quite impossible unfortunately. In 2007+ OOXML format diffing does give the basic answer, looking at xl/worksheets/sheet1.xml In normal view:

<sheetViews>
 <sheetView rightToLeft="1" tabSelected="1" zoomScaleNormal="100" workbookViewId="0">
</sheetViews>

在页面布局视图中:

<sheetViews>
 <sheetView rightToLeft="1" tabSelected="1" view="pageLayout" zoomScaleNormal="100" workbookViewId="0"/>
</sheetViews>

这是每张纸中的第二个标签.是否有任何 XSSF API 选项来编辑该属性?(或者解决问题的唯一方法是解压缩文件,编辑并重新打包)

That is the second tag in each sheet. Is there any XSSF API option to edit that attribute? (or the only solution to the problem would be unpacking the file, editing it and repacking)

谢谢!

推荐答案

XSSF 不会直接暴露这个,但如果你愿意,你可以得到它

XSSF doesn't expose this directly, but you can get at it if you want

XSSFSheet 对象,调用 getCTWorksheet 以获取支持该工作表的低级 XML 对象.CTWorksheet 提供了一个 getSheetViews 方法.你会喜欢这样的:

From the XSSFSheet object, call getCTWorksheet to get the low level XML object backing the sheet. CTWorksheet provides a getSheetViews method. You'll like want something like:

 CTSheetView view = sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0);
 view.setView(STSheetViewType.PAGE_LAYOUT);

这篇关于使用apache poi在excel文件中设置页面查看模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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