use of org.odftoolkit.odfdom.doc.OdfSpreadsheetDocument in project OpenRefine by OpenRefine.
the class OdsExporter method export.
@Override
public void export(final Project project, Properties params, Engine engine, OutputStream outputStream) throws IOException {
final OdfSpreadsheetDocument odfDoc;
try {
odfDoc = OdfSpreadsheetDocument.newSpreadsheetDocument();
} catch (Exception e) {
throw new IOException("Failed to create spreadsheet", e);
}
TabularSerializer serializer = new TabularSerializer() {
OdfTable table;
//int rowCount = 0;
@Override
public void startFile(JSONObject options) {
table = OdfTable.newTable(odfDoc);
table.setTableName(ProjectManager.singleton.getProjectMetadata(project.id).getName());
}
@Override
public void endFile() {
}
@Override
public void addRow(List<CellData> cells, boolean isHeader) {
OdfTableRow r = table.appendRow();
for (int i = 0; i < cells.size(); i++) {
// implicitly creates cell
OdfTableCell c = r.getCellByIndex(i);
CellData cellData = cells.get(i);
if (cellData != null && cellData.text != null && cellData.value != null) {
Object v = cellData.value;
if (v instanceof Number) {
c.setDoubleValue(((Number) v).doubleValue());
} else if (v instanceof Boolean) {
c.setBooleanValue(((Boolean) v).booleanValue());
} else if (v instanceof Date) {
Calendar cal = Calendar.getInstance();
cal.setTime((Date) v);
c.setDateValue(cal);
} else if (v instanceof Calendar) {
c.setDateValue((Calendar) v);
} else {
c.setStringValue(cellData.text);
}
if (cellData.link != null) {
// TODO: How do we do output hyperlinks?
}
}
}
}
};
CustomizableTabularExporterUtilities.exportRows(project, engine, params, serializer);
try {
odfDoc.save(outputStream);
} catch (Exception e) {
throw new IOException("Error saving spreadsheet", e);
}
outputStream.flush();
}
Aggregations