HSSFCellStyle.UserStyleName always returns NULL in 1.2.4

Nov 22, 2012 at 2:28 PM

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:

get
            {
                StyleRecord sr = workbook.GetStyleRecord(index);
                if (sr == null)
                {
                    return null;
                }
                //if (sr.IsBuiltin)
                if (sr.IsBuiltin && sr.Name == null)
                {
                    return null;
                }
                return sr.Name;
            }

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?

Coordinator
Nov 22, 2012 at 10:04 PM

Have you tried 1.2.5?

Dec 18, 2012 at 3:58 PM
Edited Dec 18, 2012 at 4:00 PM

I tried 1.2.5 a while ago but reverted back to 1.2.4 for other reasons.  The code in 1.2.5 looks like it behaves in the same way as 1.2.4?  If not, please could you point me in the direction of what has been changed?  Thanks.