Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: XLWorkbook.Save causes spreadsheet to lose data

$
0
0
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 .....>
<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;

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>