Frage

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.

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>

In page layout view:

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

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)

Thanks!

War es hilfreich?

Lösung

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

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top