Bug 49185 - Implementation of HSSFName#getComment - descriptive text or comment record
Summary: Implementation of HSSFName#getComment - descriptive text or comment record
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.7-dev
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2010-04-26 06:25 UTC by Andrew Shirley
Modified: 2010-07-16 12:03 UTC (History)
0 users

a spreadsheet with a single named range with a comment (16.50 KB, application/vnd.ms-excel)
2010-04-26 06:25 UTC, Andrew Shirley
patch to support 'NameCommentRecord's (20.12 KB, patch)
2010-07-05 09:52 UTC, Andrew Shirley
Details | Diff
test-data file for test added in previous patch (16.50 KB, application/vnd.ms-excel)
2010-07-05 09:54 UTC, Andrew Shirley

Note You need to log in before you can comment on or make changes to this bug.
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