Bug 47182 - Link between HSSFCell and StyleRecord is broken
Summary: Link between HSSFCell and StyleRecord is broken
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2009-05-11 06:45 UTC by Sarah
Modified: 2011-06-25 13:07 UTC (History)
0 users

ExcelBeobachtung.java - the source code (1.29 KB, application/octet-stream)
2009-05-11 10:53 UTC, Sarah
excel file (19.00 KB, application/octet-stream)
2009-05-11 10:54 UTC, Sarah
screen shot from debugger (183.04 KB, image/jpeg)
2009-05-11 10:59 UTC, Sarah

Note You need to log in before you can comment on or make changes to this bug.
Description Sarah 2009-05-11 06:45:07 UTC
I need the UserStyleName of a cell. But when i call getUserName(), it always returns null.

	// used version: poi-3.5-beta5, jdk1.6.0_04, excel 97
	FileInputStream input= new FileInputStream(filename);
	HSSFWorkbook worksheet= new HSSFWorkbook(input);
	HSSFSheet sheet = worksheet.getSheetAt(0);
	HSSFRow row = sheet.getRow(0);
	HSSFCell cellBeobachtung= row.getCell(0);
	HSSFCellStyle cellStyleBeobachtung= cellBeobachtung.getCellStyle();
	System.out.println("cellStyleBeobachtung, user name: " + cellStyleBeobachtung.getUserStyleName());

After putting some effort in it, I figured out, that the StyleRecord is correctly constructed (number 231 in the records array). But the xf reference number is 63 which is a dummy value, indicating that the reference is stored elsewhere:

   OpenOffice, Microsoft Excel File Format, Chapter 2.5.13 Cell Attributes (BIFF2)
   If a real XF index greater than 62 is used, the XF index field always contains the value 63, and an
IXFE record (➜5.62) occurs in front of a cell record. The IXFE record contains the correct index of the XF record.

The method to get the appropriate UserStyleName has two problems. On the one hand it assumes that all StyleRecords follow directly after the ExtendenFormatRecords. But there are heaps of UnknownRecords in between the StyleRecords.
On the other hand are the xf reference numbers which have to treat the number 63 in a different way.

For my excel files, the values are stored in MulRKRecord, there the xf value is 63 (dummy value) and the rk value is 1083088896. Does anybody know what this rk value means. Can I navigate with this rk value to the StyleRecord?

(I will attach the java source, excel file and 2 printscreens later, since my internet access is restricted at this place.)
Comment 1 Sarah 2009-05-11 10:53:18 UTC
Created attachment 23644 [details]
ExcelBeobachtung.java - the source code
Comment 2 Sarah 2009-05-11 10:54:22 UTC
Created attachment 23645 [details]
excel file
Comment 3 Sarah 2009-05-11 10:59:48 UTC
Created attachment 23646 [details]
screen shot from debugger

This screenshot shows the code snippet which fails to find the StyleRecord (with the name Beobachtung). The StyleRecord is selected in the variables view, it exists, but the method won't find it.
Comment 4 Yegor Kozlov 2011-06-25 13:07:01 UTC
In your case the user style is a parent of the cell style. The correct code to check UserStyleName is below:

        HSSFCellStyle style = cell.getCellStyle();
        if(style.getParentStyle() != null){
            HSSFCellStyle  parentStyle = style.getParentStyle();
            String styleName = parentStyle.getUserStyleName();