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

Created Unassigned: AutoFit(AutoFitColumns) cause NullReferenceException [14905]

$
0
0
When I set "user define format" on cell , AutoFit cause NullReferenceException.

I saw ExcelRangeBase.cs and discovered some formats don't exist in styles.NumberFormats , so the variable "nf" is null.

I think "if(nf != null){..." statement is needed before using nf .

```
private string GetFormatedText(bool forWidthCalc)
{
object v = Value;
if (v == null) return "";
var styles = Worksheet.Workbook.Styles;
var nfID = styles.CellXfs[StyleID].NumberFormatId;
ExcelNumberFormatXml.ExcelFormatTranslator nf = null;
for (int i = 0; i < styles.NumberFormats.Count; i++)
{
if (nfID == styles.NumberFormats[i].NumFmtId)
{
nf = styles.NumberFormats[i].FormatTranslator;
break;
}
}

string format, textFormat;
if (forWidthCalc)
{
format = nf.NetFormatForWidth; // Raise NullReferenceException ...
textFormat = nf.NetTextFormatForWidth;
}
...
```

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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