Search in sources :

Example 1 with OpenXMLWorkbookResource

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

the class XlsFlexiTableExporter method export.

@Override
public MediaResource export(FlexiTableComponent ftC, List<FlexiColumnModel> columns, Translator translator) {
    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(columns, translator, sheet, workbook);
                createData(ftC, columns, translator, sheet, workbook);
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : 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 2 with OpenXMLWorkbookResource

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

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 3 with OpenXMLWorkbookResource

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

the class XlsMembersExport method export.

public MediaResource export(List<Identity> rows, Map<Identity, StringBuilder> members, Translator translator, List<UserPropertyHandler> userPropertyHandlers) {
    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(userPropertyHandlers, translator, sheet, workbook);
                createData(members, rows, userPropertyHandlers, sheet);
            } catch (IOException e) {
                log.error("Unable to export xlsx", e);
            }
        }
    };
}
Also used : 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 4 with OpenXMLWorkbookResource

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

the class CustomDBController method exportDb.

private void exportDb(UserRequest ureq, final String category) {
    final ICourse course = CourseFactory.loadCourse(courseKey);
    String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
    MediaResource export = new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                // create the headers
                Row headerRow = exportSheet.newRow();
                headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
                for (CourseDBEntry entry : content) {
                    User user = entry.getIdentity().getUser();
                    String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
                    Row dataRow = exportSheet.newRow();
                    dataRow.addCell(0, entry.getCategory(), null);
                    dataRow.addCell(1, name, null);
                    if (StringHelper.containsNonWhitespace(entry.getName())) {
                        dataRow.addCell(2, entry.getName(), null);
                    }
                    if (entry.getValue() != null) {
                        dataRow.addCell(3, entry.getValue().toString(), null);
                    }
                }
            } catch (IOException e) {
                logError("", e);
            }
        }
    };
    ureq.getDispatchResult().setResultingMediaResource(export);
}
Also used : User(org.olat.core.id.User) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) OutputStream(java.io.OutputStream) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ICourse(org.olat.course.ICourse) MediaResource(org.olat.core.gui.media.MediaResource) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

Example 5 with OpenXMLWorkbookResource

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

the class CustomDBController method exportDb.

private void exportDb(UserRequest ureq, final String category) {
    final ICourse course = CourseFactory.loadCourse(courseKey);
    String label = ExportUtil.createFileNameWithTimeStamp("DBS_" + course.getCourseTitle(), "xls");
    MediaResource export = new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                List<CourseDBEntry> content = courseDbManager.getValues(course, null, category, null);
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                // create the headers
                Row headerRow = exportSheet.newRow();
                headerRow.addCell(0, translate("customDb.category"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(1, translate("customDb.entry.identity"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(2, translate("customDb.entry.name"), workbook.getStyles().getHeaderStyle());
                headerRow.addCell(3, translate("customDb.entry.value"), workbook.getStyles().getHeaderStyle());
                for (CourseDBEntry entry : content) {
                    User user = entry.getIdentity().getUser();
                    String name = user.getProperty(UserConstants.FIRSTNAME, null) + " " + user.getProperty(UserConstants.LASTNAME, null);
                    Row dataRow = exportSheet.newRow();
                    dataRow.addCell(0, entry.getCategory(), null);
                    dataRow.addCell(1, name, null);
                    if (StringHelper.containsNonWhitespace(entry.getName())) {
                        dataRow.addCell(2, entry.getName(), null);
                    }
                    if (entry.getValue() != null) {
                        dataRow.addCell(3, entry.getValue().toString(), null);
                    }
                }
            } catch (IOException e) {
                logError("", e);
            }
        }
    };
    ureq.getDispatchResult().setResultingMediaResource(export);
}
Also used : User(org.olat.core.id.User) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) OutputStream(java.io.OutputStream) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ICourse(org.olat.course.ICourse) MediaResource(org.olat.core.gui.media.MediaResource) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

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