Upgrade to ExcelNumberFormat 1.1.0 has caused the ClosedXML AdjustColumnWidths method to misbehave
See original GitHub issueRead and complete the full issue template
Do not randomly delete sections. They are here for a reason.
Do you want to request a feature or report a bug?
- Bug
- Feature
- Question
Did you test against the latest CI build?
- Yes
- No
If you answered No
, please test with the latest development build first.
Version of ClosedXML
0.95.4
What is the current behavior?
AdjustColumnWidths is not behaving appropriately since upgrading to ExcelNumberFormat 1.1.0. Some columns are wider than the data in the columns and some are narrower.
What is the expected behavior or new feature?
AdjustColumnWidths should behave appropriately - setting all columns to the width of the data in the column. This worked perfectly with ExcelNumberFormat 1.0.10, but fails since upgrading.
Is this a regression from the previous version?
Tested regression version of ExcelNumberFormat
Reproducibility
This is an important section. Read it carefully. Failure to do so will cause a ‘RTFM’ comment.
Without a code sample, it is unlikely that your issue will get attention. Don’t be lazy. Do the effort and assist the developers to reproduce your problem. Code samples should be minimal complete and verifiable. Sample spreadsheets should be attached whenever applicable. Remove sensitive information.
Code to reproduce problem:
private static void Main(string[] args)
{
XLWorkbook wb = new XLWorkbook();
IXLWorksheet ws = wb.Worksheets.Add();
ws.Row(1).Style.Font.Bold = true;
ws.Column(1).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right);
ws.Column(2).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right);
ws.Column(3).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Right);
ws.Cell(1, 1).SetValue("Date");
ws.Cell(2, 1).SetValue(DateTime.Now.Date);
ws.Cell(3, 1).SetValue(DateTime.Now.Date.AddDays(7));
ws.Cell(1, 2).SetValue($"First{Environment.NewLine}Amount");
ws.Cell(2, 2).SetValue(123456.78).Style.NumberFormat.Format = "[$$-en-US] #,##0.00";
ws.Cell(3, 2).SetValue(12345678).Style.NumberFormat.Format = "[$$-en-US] #,##0.00";
ws.Cell(1, 3).SetValue($"Second{Environment.NewLine}Amount");
ws.Cell(2, 3).SetValue(1.23).Style.NumberFormat.Format = "[$$-en-US] #,##0.00";
ws.Cell(3, 3).SetValue(123).Style.NumberFormat.Format = "[$$-en-US] #,##0.00";
ws.Cell(1, 4).SetValue("Text");
ws.Cell(2, 4).SetValue("Go");
ws.Cell(3, 4).SetValue("Go Go Go");
ws.Columns().AdjustToContents();
wb.SaveAs(@"c:\temp\test.xlsx");
}
- I attached a sample spreadsheet. (You can drag files on to this issue) test with new ExcelNumberFormat.xlsx test with old ExcelNumberFormat.xlsx
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
Here you go. It looks like cell.GetFormattedString() method is not returning the formatted string with ExcelNumberFormat 1.1.0 where with version 1.0.10 it was.
Using ExcelNumberFormat 1.0.10:
Using ExcelNumberFormat 1.1.0:
I think this is caused by https://github.com/andersnm/ExcelNumberFormat/issues/31