Bug 49185

Summary: Implementation of HSSFName#getComment - descriptive text or comment record
Product: POI Reporter: Andrew Shirley <aks>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.7-dev   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: a spreadsheet with a single named range with a comment
patch to support 'NameCommentRecord's
test-data file for test added in previous patch

Description Andrew Shirley 2010-04-26 06:25:29 UTC
Created attachment 25352 [details]
a spreadsheet with a single named range with a comment

I am trying to read a spreadsheet created in excel 2007 and saved as an "Excel 97-2003 Workbook". Using the new UI for the name manager, I create a Name whose name is "foobarName" and whose comment is "This is a comment". POI claims that the comment for the name is blank. It should be noted that reading the xlsx file, POI correctly returns the comment.

I have looked at the xls file produced by excel (attached) and noticed an unknown record (0x894). This seems to be the record intended to store the comment for names.

The current implementation of HSSFName#getComment uses the "Description text" field of the NAME record. Unfortunately I have no idea what "Description text" is supposed to contain and so I'm loathed to suggest simply ignoring this field in favour of the NAMECMT record.

I am currently working on a patch for support of NAMECMT records but would like to know what the correct behaviour should be.
Comment 1 Nick Burch 2010-04-26 06:39:23 UTC
I think NameCmt may be quite a new thing

HSSFName is backed by a NameRecord (sid=0x18), which is called a "Lbl" in the newer Microsoft docs (page 323 in v20091214)

HSSFName stores the comment in the DescriptionText field of NameRecord (field 15).

Interestingly, the latest docs on Lbl says that the various extra length fields (eg the description) are reserved and must be zero, so clearly Microsoft have changed something at some point. This would explain why new files don't have comments in the same way

I'd suggest you add support for the NameCmt record, and update HSSFName to check it if the description text on a NameRecord is of length zero
Comment 2 Andrew Shirley 2010-07-05 09:52:31 UTC
Created attachment 25705 [details]
patch to support 'NameCommentRecord's

This patch parses and stores NameCommentRecord records and changes the implementation of HSSFName#getComment to use it's Description text and if that isn't available an associated NameCommentRecord.
Comment 3 Andrew Shirley 2010-07-05 09:54:23 UTC
Created attachment 25706 [details]
test-data file for test added in previous patch

A file for testing. This should be placed in test-data/spreadsheet
Comment 4 Nick Burch 2010-07-16 12:03:51 UTC
Thanks for this. Applied in r964845, along with some tweaks to make changes possible, and to support renaming names carrying their comments with them