I am just curious about one thing on the org.apache.poi.hssf.usermodel.HSSFCellStyle
HSSFCellStyle.setUserStyleName will create a style record, which is a form of an XF but is incompatible to the
HSSFWorkbook.getCellStyleAt( short index ) as, though I'm not fully sure, workbook.getExFormatAt( short index )
expects an ExtendedFormatRecord but setUserStyleName creates a Style Record. You can't convert an ExtendedFormatRecord to
a StyleRecord as the classes are siblings of each other and will get a ClassCastException after using something like
HSSFOptimiser.optimiseCellStyle( HSSFWorkbook wb ). My suggestion is to use something like InternalWorkbook.createCellStyleXf in the setUserStyleName function. So this is a suggested way of the function:
public void setUserStyleName(
String styleName) {
ExtendedFormatRecord efr = _workbook.getExFormatRecord(_index);
if(efr == null) {
efr = _workbook.createCellXF();
}
// All Style records start as "builtin", but generally
// only 20 and below really need to be
if(sr.isBuiltin() && _index <= 20) {
throw new IllegalArgumentException("Unable to set user specified style names for built in styles!");
}
// The name needs to be defined as a member in ExtendedFormatRecord
//sr.setName(styleName);
}
public String getUserStyleName() {
ExtendedFormatRecord efr = _workbook.getExFormatRecord(_index);
if(efr == null) {
return null;
}
if(efr.isBuiltin()) {
return null;
}
return efr.getName();
}
But the ExtendedFormatRecord needs to have the isBuiltin defined using perhaps the example from the StyleRecord class