XmlException, IOException {
XSSFWorkbook document = (XSSFWorkbook) extractor.getDocument();
for (int i = 0; i < document.getNumberOfSheets(); i++) {
xhtml.startElement("div");
XSSFSheet sheet = (XSSFSheet) document.getSheetAt(i);
xhtml.element("h1", document.getSheetName(i));
// Header(s), if present
extractHeaderFooter(sheet.getFirstHeader(), xhtml);
extractHeaderFooter(sheet.getOddHeader(), xhtml);
extractHeaderFooter(sheet.getEvenHeader(), xhtml);
xhtml.startElement("table");
xhtml.startElement("tbody");
// Rows and cells
for (Object rawR : sheet) {
xhtml.startElement("tr");
Row row = (Row) rawR;
for (Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
xhtml.startElement("td");
Cell cell = ri.next();
int type = cell.getCellType();
if (type == Cell.CELL_TYPE_FORMULA) {
type = cell.getCachedFormulaResultType();
}
if (type == Cell.CELL_TYPE_STRING) {
xhtml.characters(cell.getRichStringCellValue()
.getString());
} else if (type == Cell.CELL_TYPE_NUMERIC) {
CellStyle style = cell.getCellStyle();
xhtml.characters(
formatter.formatRawCellContents(cell.getNumericCellValue(),
style.getDataFormat(),
style.getDataFormatString()));
} else {
XSSFCell xc = (XSSFCell) cell;
String rawValue = xc.getRawValue();
if (rawValue != null) {
xhtml.characters(rawValue);
}
}
// Output the comment in the same cell as the content
Comment comment = cell.getCellComment();
if (comment != null) {
xhtml.characters(comment.getString().getString());
}
xhtml.endElement("td");
}
xhtml.endElement("tr");
}
xhtml.endElement("tbody");
xhtml.endElement("table");
// Finally footer(s), if present
extractHeaderFooter(sheet.getFirstFooter(), xhtml);
extractHeaderFooter(sheet.getOddFooter(), xhtml);
extractHeaderFooter(sheet.getEvenFooter(), xhtml);
xhtml.endElement("div");
}
}