Search in sources :

Example 11 with OpenXMLWorkbookResource

use of org.olat.core.util.openxml.OpenXMLWorkbookResource in project openolat by klemens.

the class DefaultXlsTableExporter method export.

/**
 * @see org.olat.core.gui.components.table.TableExporter#export(org.olat.core.gui.components.table.Table)
 */
@Override
public MediaResource export(final Table table) {
    Translator translator = table.getTranslator();
    int cdcnt = table.getColumnCount();
    int rcnt = table.getRowCount();
    String label = "TableExport_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
    return new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                OpenXMLWorksheet sheet = workbook.nextWorksheet();
                createHeader(table, translator, cdcnt, sheet, workbook);
                createData(table, cdcnt, rcnt, sheet);
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) OutputStream(java.io.OutputStream) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date)

Example 12 with OpenXMLWorkbookResource

use of org.olat.core.util.openxml.OpenXMLWorkbookResource 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);
            }
        }
    };
}
Also used : Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) InstantMessage(org.olat.instantMessaging.InstantMessage) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date)

Aggregations

IOException (java.io.IOException)12 OutputStream (java.io.OutputStream)12 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)12 OpenXMLWorkbookResource (org.olat.core.util.openxml.OpenXMLWorkbookResource)12 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)12 Date (java.util.Date)10 Translator (org.olat.core.gui.translator.Translator)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 ICourse (org.olat.course.ICourse)4 File (java.io.File)2 ObjectOutputStream (java.io.ObjectOutputStream)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 MediaResource (org.olat.core.gui.media.MediaResource)2 User (org.olat.core.id.User)2 ShieldOutputStream (org.olat.core.util.io.ShieldOutputStream)2 FileResourceManager (org.olat.fileresource.FileResourceManager)2 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)2 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)2 InstantMessage (org.olat.instantMessaging.InstantMessage)2