Search in sources :

Example 31 with OpenXMLWorksheet

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

the class QTI21ArchiveFormat method exportWorkbook.

public void exportWorkbook(OutputStream exportStream) {
    RepositoryEntry testEntry = searchParams.getTestEntry();
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    // content
    final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
    final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
    try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(exportStream, 1)) {
        // headers
        OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
        exportSheet.setHeaderRows(2);
        writeHeaders_1(exportSheet, workbook);
        writeHeaders_2(exportSheet, workbook);
        writeData(sessions, responses, exportSheet, workbook);
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) RepositoryEntry(org.olat.repository.RepositoryEntry) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) File(java.io.File) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) IOException(java.io.IOException)

Example 32 with OpenXMLWorksheet

use of org.olat.core.util.openxml.OpenXMLWorksheet 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)32 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)32 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)32 OutputStream (java.io.OutputStream)16 Date (java.util.Date)14 OpenXMLWorkbookResource (org.olat.core.util.openxml.OpenXMLWorkbookResource)14 Translator (org.olat.core.gui.translator.Translator)10 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)10 Identity (org.olat.core.id.Identity)6 ICourse (org.olat.course.ICourse)6 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)6 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ZipOutputStream (java.util.zip.ZipOutputStream)4 CoreSpringFactory (org.olat.core.CoreSpringFactory)4 User (org.olat.core.id.User)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 OLog (org.olat.core.logging.OLog)4