Apache POIソースからXSSFSheetXMLHandlerのソースコードを取得します。それはかなり簡単です。
このクラスを複製して、SheetHandlerを渡すよりも必要なものをすべて行うことが理にかなっています。私は大規模なXLSXファイルを処理するメモリの問題に遭遇する前に、ユーザーAPIで行ったことのすべて(スタイル、色、枠線、結合されたセルなど)を達成することができました。
たとえば、startElementの下の "c"ハンドラを少し変更しました。 XSSFCellStyleをクラスのプロパティとして保存してから、cellHandlerで使用できます。
// c => cell
else if ("c".equals(localName)) {
// Set up defaults.
this.nextDataType = xssfDataType.NUMBER;
this.formatIndex = -1;
this.formatString = null;
cellRef = attributes.getValue("r");
String cellType = attributes.getValue("t");
String cellStyleStr = attributes.getValue("s");
if (stylesTable != null) {
if (cellStyleStr != null) {
int styleIndex = Integer.parseInt(cellStyleStr);
this.cellStyle = stylesTable.getStyleAt(styleIndex);
} else if (stylesTable.getNumCellStyles() > 0) {
this.cellStyle = stylesTable.getStyleAt(0);
}
}
と、(例えばcellHandlerで)後で使用:
XSSFFont cellFont = cellStyle.getFont();
if(cellFont.getXSSFColor() != null) {
// set hex colour in style. drop first 2 hex characters since they represent alpha
styles.put(CSS_COLOR, "#"+cellFont.getXSSFColor().getARGBHex().substring(2));
}
結合されたセル:
else if ("mergeCell".equals(localName)) {
if (attributes.getValue("ref") != null) {
CellRangeAddress cra = CellRangeAddress.valueOf(attributes.getValue("ref"));
// store merged cell ranges in hashmap?
}
}