use of org.olat.core.util.openxml.OpenXMLWorksheet.Row in project openolat by klemens.
the class ChatLogHelper method logMediaResource.
public MediaResource logMediaResource(OLATResourceable ores, Locale locale) {
Translator translator = Util.createPackageTranslator(ChatController.class, locale);
String tableExportTitle = translator.translate("logChat.export.title");
String label = tableExportTitle + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
return new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
// headers
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
Row headerRow = exportSheet.newRow();
headerRow.addCell(0, "User", workbook.getStyles().getHeaderStyle());
headerRow.addCell(1, "Date", workbook.getStyles().getHeaderStyle());
headerRow.addCell(2, "Content", workbook.getStyles().getHeaderStyle());
// content
List<InstantMessage> messages = imDao.getMessages(ores, null, 0, -1);
for (InstantMessage message : messages) {
Row dataRow = exportSheet.newRow();
dataRow.addCell(0, message.getFromNickName(), null);
dataRow.addCell(1, message.getCreationDate(), workbook.getStyles().getDateStyle());
dataRow.addCell(2, message.getBody(), null);
}
} catch (IOException e) {
log.error("", e);
}
}
};
}
Aggregations