A proxy HSSFListener that keeps track of the document
formatting records, and provides an easy way to look
up the format strings used by cells from their ids.
| Method from org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener Detail: |
public int getFormatIndex(CellValueRecordInterface cell) {
ExtendedFormatRecord xfr = (ExtendedFormatRecord)
xfRecords.get(cell.getXFIndex());
if(xfr == null) {
System.err.println("Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we don't have that");
return -1;
}
return xfr.getFormatIndex();
}
Returns the index of the format string, used by your cell,
or -1 if none found |
public String getFormatString(int formatIndex) {
String format = null;
if(formatIndex >= HSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) {
FormatRecord tfr = (FormatRecord)customFormatRecords.get(new Integer(formatIndex));
if(tfr == null) {
System.err.println("Requested format at index " + formatIndex + ", but it wasn't found");
} else {
format = tfr.getFormatString();
}
} else {
format = HSSFDataFormat.getBuiltinFormat((short)formatIndex);
}
return format;
}
Returns the format string, eg $##.##, for the
given number format index. |
public String getFormatString(CellValueRecordInterface cell) {
int formatIndex = getFormatIndex(cell);
if(formatIndex == -1) {
// Not found
return null;
}
return getFormatString(formatIndex);
}
Returns the format string, eg $##.##, used
by your cell |
public void processRecord(Record record) {
// Handle it ourselves
processRecordInternally(record);
// Now pass on to our child
childListener.processRecord(record);
}
Process this record ourselves, and then
pass it on to our child listener |
public void processRecordInternally(Record record) {
if(record instanceof FormatRecord) {
FormatRecord fr = (FormatRecord) record;
customFormatRecords.put(new Integer(fr.getIndexCode()), fr);
}
if(record instanceof ExtendedFormatRecord) {
ExtendedFormatRecord xr = (ExtendedFormatRecord) record;
xfRecords.add(xr);
}
}
Process the record ourselves, but do not
pass it on to the child Listener. |