I am using NPOI 1.2.4 and have noticed that I cannot retrieve a custom cell style by name as the UserStyleName property always returns null.
Having looked through the NPOI source, it appears that a newly create HSSFCellStyle object (created using HSSFWorkbook.CreateCellStyle) will always have an internal StyleRecord that has its IsBuiltin flag set to true. When this is the case, the get
for UserStyleName will always return null, even though it is not a built in style.
A workaround for this might be to change the get to:
StyleRecord sr = workbook.GetStyleRecord(index);
if (sr == null)
if (sr.IsBuiltin && sr.Name == null)
However, for objects created with HSSFWorkbook.CreateCellStyle, would it not be more sensible for the default for IsBuiltin to be false, as you've just asked for it to be created?
Or, am I missing something obvious?