I have a similar, yet simpler issue.
I have an existing .xlsx file, setup up with a page-break view. When the spreadsheet is opened and saved, the page-break view is stripped.
The problem is, that the value is never loaded into memory from the original document.
Example:
Original document:
<worksheet .....>
...
Calling the following, very simple code on the file, will strip the view-attribute of the OpenXml-file:
Its a bit annoying that a simple open/close operation modifies the file, but the workaround in my case was simple. I always want a specific value, not nessesarily the one defined in the original document. Therefore I just set it before saving, like this:
workbook.Worksheets.First().SheetView.View = XLSheetViewOptions.PageBreakPreview;
I have an existing .xlsx file, setup up with a page-break view. When the spreadsheet is opened and saved, the page-break view is stripped.
The problem is, that the value is never loaded into memory from the original document.
Example:
Original document:
<worksheet .....>
<dimension ..../>
<sheetViews>
<sheetView tabSelected="1" __view="pageBreakPreview"__ zoomScaleNormal="100" zoomScaleSheetLayoutView="100" workbookViewId="0">
......
Calling the following, very simple code on the file, will strip the view-attribute of the OpenXml-file:
public void OpenCloseWorkbook(string fileName, string sheetName)
{
var workbook = new XLWorkbook(fileName);
workbook.Save();
}
...<sheetView tabSelected="1" zoomScaleNormal="100" zoomScaleSheetLayoutView="100" workbookViewId="0">
...Its a bit annoying that a simple open/close operation modifies the file, but the workaround in my case was simple. I always want a specific value, not nessesarily the one defined in the original document. Therefore I just set it before saving, like this:
workbook.Worksheets.First().SheetView.View = XLSheetViewOptions.PageBreakPreview;