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

Commented Issue: Saving workbook creates extra NumFmt elements [8369]

$
0
0
It appears that each time a workbook is saved a empty NumFmt (NumberingFormat) element is appended in the stylesheet. Once this is done enough times, it will start stepping on the built-in formats. I was noticing this with the percent format which I belive is #10.

The excel file attached has one cell, formatted as a percentage. After 9 saves, the formatting is lost.
In my practical application the stream was being passed around and many classes were opening a workbook from the stream and saving back to the stream.

This was the latest version, 77207



byte[] calculatedExcelStreamBytes = File.ReadAllBytes("c:\\LoseFormatTest.xlsx");

using (MemoryStream calculatedExcelStream = new MemoryStream())
{
calculatedExcelStream.Write(calculatedExcelStreamBytes, 0, calculatedExcelStreamBytes.Length);
XLWorkbook b = new XLWorkbook(calculatedExcelStream);

b.Save(); // Each save will increase the number of formats written, looking to step on built-in formats
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save();
b.Save(); // At this point we are stepping on the percent format
b.Save();
b.Save();
b.Save();
b.Save();

using (FileStream fs = new FileStream("C:\\LoseFormatTest.Modify.xlsx", FileMode.Create, FileAccess.Write))
{
calculatedExcelStream.WriteTo(fs);
fs.Flush();
fs.Close();
}
}
Comments: ** Comment from web user: FeelingPhoggy **

I am having the same issue, as far as I can tell.

I have a workbook with multiple worksheets. When make changes to 1 worksheet and then save the workbook, date formatting on a completely different worksheet than I edited is lost and the dates do not appear as they did before the .Save() operation.

Any help or tips for workarounds would be great.


Viewing all articles
Browse latest Browse all 1877

Trending Articles



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