Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Commented Unassigned: Delete column with save corrupts output file [15196]

$
0
0
The DeleteColumn appears to work in memory but when the package is saved following a delete column the file is corrupt and so is the in memory version of the associated worksheet.

I've attached a file that contains three NUnit tests that demonstrate the problem. Hopefully you can correct this ASAP or suggest a workaround. Let me know if I can help with this further as it is now holding me up.



Comments: I think the error is in this section of code in WorkSheet.DeleteColumn() ``` foreach (var tbl in Tables) { if (columnFrom > tbl.Address.Start.Column && columnFrom <= tbl.Address.End.Column) { var node = tbl.Columns[0].TopNode.ParentNode; var ix = columnFrom - tbl.Address.Start.Column + 1; for (int i = 0; i < columns; i++) { if (node.ChildNodes.Count > ix) { node.RemoveChild(node.ChildNodes[ix]); } } tbl._cols = new ExcelTableColumnCollection(tbl); } ``` I believe there are two area where there is a problem ... ``` if (columnFrom > tbl.Address.Start.Column && columnFrom <= tbl.Address.End.Column) ``` The first test should be ">=" otherwise column 1 is missed if this is deleted. The second is where the ix (the index into the ChildNodes array) is calculated. This has a +1 on the end which means that it points to the wrong column in the xml node. The corrected code is: ``` foreach (var tbl in Tables) { if (columnFrom >= tbl.Address.Start.Column && columnFrom <= tbl.Address.End.Column) { var node = tbl.Columns[0].TopNode.ParentNode; var ix = columnFrom - tbl.Address.Start.Column; for (int i = 0; i < columns; i++) { if (node.ChildNodes.Count > ix) { node.RemoveChild(node.ChildNodes[ix]); } } tbl._cols = new ExcelTableColumnCollection(tbl); } ``` This does work for my selective test - deleting column 1 from a 4 column spreadsheet. I'll continue to test for column deletion and revert.

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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