use of org.olat.core.util.openxml.OpenXMLWorksheet.Row in project OpenOLAT by OpenOLAT.
the class XlsMembersExport method createHeader.
private void createHeader(List<UserPropertyHandler> userPropertyHandlers, Translator translator, OpenXMLWorksheet sheet, OpenXMLWorkbook workbook) {
Row headerRow = sheet.newRow();
for (int c = 0; c < userPropertyHandlers.size(); c++) {
UserPropertyHandler handler = userPropertyHandlers.get(c);
String header = translator.translate("form.name." + handler.getName());
headerRow.addCell(c, header, workbook.getStyles().getHeaderStyle());
}
Translator roleTranslator = Util.createPackageTranslator(RulesDataModel.class, translator.getLocale());
headerRow.addCell(userPropertyHandlers.size(), roleTranslator.translate("rules.role"));
}
use of org.olat.core.util.openxml.OpenXMLWorksheet.Row 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);
}
use of org.olat.core.util.openxml.OpenXMLWorksheet.Row in project openolat by klemens.
the class QuestionItemAuditLogExport method addContent.
@SuppressWarnings("deprecation")
private void addContent(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
for (QuestionItemAuditLog logEntry : auditLog) {
int pos = 0;
Row row = exportSheet.newRow();
Date creationDate = logEntry.getCreationDate();
row.addCell(pos++, creationDate, workbook.getStyles().getDateTimeStyle());
row.addCell(pos++, logEntry.getAction());
QuestionItem item = null;
if (logEntry.getQuestionItemKey() != null) {
item = qpoolService.toAuditQuestionItem(logEntry.getAfter());
}
if (item != null) {
row.addCell(pos++, item.getTitle());
row.addCell(pos++, item.getTopic());
if (qpoolModule.isTaxonomyEnabled()) {
row.addCell(pos++, item.getTaxonomicPath());
}
if (qpoolModule.isEducationalContextEnabled()) {
row.addCell(pos++, getTranslatedContext(item.getEducationalContext()));
}
row.addCell(pos++, item.getKeywords());
row.addCell(pos++, item.getAdditionalInformations());
row.addCell(pos++, item.getCoverage());
row.addCell(pos++, item.getLanguage());
row.addCell(pos++, getTranslatedAssessmentType(item.getAssessmentType()));
row.addCell(pos++, getTranslatedItemType(item.getItemType()));
row.addCell(pos++, item.getEducationalLearningTime());
row.addCell(pos++, format(item.getDifficulty()));
row.addCell(pos++, format(item.getStdevDifficulty()));
row.addCell(pos++, format(item.getDifferentiation()));
row.addCell(pos++, String.valueOf(item.getNumOfAnswerAlternatives()));
row.addCell(pos++, String.valueOf(item.getUsage()));
row.addCell(pos++, item.getItemVersion());
row.addCell(pos++, getTranslatedStatus(item.getQuestionStatus()));
} else {
pos += 16;
if (qpoolModule.isTaxonomyEnabled()) {
pos++;
}
if (qpoolModule.isEducationalContextEnabled()) {
pos++;
}
}
if (licenseModule.isEnabled(licenseHandler)) {
License license = licenseService.licenseFromXml(logEntry.getLicenseAfter());
if (license != null) {
row.addCell(pos++, license.getLicenseType() != null ? license.getLicenseType().getName() : null);
row.addCell(pos++, license.getLicensor());
} else if (item != null) {
// Backward compatibility:
// Before the introduction of the LicenseService the license was stored in the item itself.
row.addCell(pos++, item.getLicense() != null ? item.getLicense().getLicenseKey() : null);
row.addCell(pos++, item.getCreator());
} else {
pos += 2;
}
}
Long authorKey = logEntry.getAuthorKey();
if (authorKey != null) {
String fullname = userManager.getUserDisplayName(authorKey);
row.addCell(pos++, fullname);
}
}
}
use of org.olat.core.util.openxml.OpenXMLWorksheet.Row in project openolat by klemens.
the class OpenXmlWorkbookTest method creationOfWorkbook.
/**
* Sadly, I can only test if our system produce a non empty file.
* @throws IOException
*/
@Test
public void creationOfWorkbook() throws IOException {
File file = File.createTempFile("workbook", "_min.xlsx");
FileOutputStream fileOut = new FileOutputStream(file);
OpenXMLWorkbook workbook = new OpenXMLWorkbook(fileOut, 1);
OpenXMLWorksheet sheet = workbook.nextWorksheet();
sheet.setHeaderRows(1);
// 0 empty
sheet.newRow();
Row row1 = sheet.newRow();
row1.addCell(1, "Title", null);
row1.addCell(2, "Titre", null);
row1.addCell(1, 1.0d, null);
Row row2 = sheet.newRow();
row2.addCell(2, "Hello", null);
row2.addCell(2, "Border", workbook.getStyles().getBorderRightStyle());
sheet.newRow();
Row row4 = sheet.newRow();
row4.addCell(5, new Date(), workbook.getStyles().getDateStyle());
workbook.close();
fileOut.flush();
IOUtils.closeQuietly(fileOut);
Assert.assertTrue(file.exists());
Assert.assertTrue(file.length() > 4096);
file.delete();
}
use of org.olat.core.util.openxml.OpenXMLWorksheet.Row in project openolat by klemens.
the class QTI21ArchiveFormat method writeHeaders_1.
private void writeHeaders_1(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
CellStyle headerStyle = workbook.getStyles().getHeaderStyle();
// first header
Row header1Row = exportSheet.newRow();
int col = 1;
if (anonymizerCallback != null) {
// anonymized name -> test duration
col += 0;
} else {
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler != null) {
col++;
}
}
// homepage -> test duration
col += 1;
}
// course node points and passed
if (courseNode instanceof AssessableCourseNode) {
AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
if (assessableCourseNode.hasScoreConfigured()) {
header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
}
if (assessableCourseNode.hasPassedConfigured()) {
if (assessableCourseNode.hasScoreConfigured()) {
col++;
} else {
header1Row.addCell(col++, translator.translate("archive.table.header.node"), headerStyle);
}
}
}
// test points, passed and dates
header1Row.addCell(col++, translator.translate("archive.table.header.test"), headerStyle);
col += 5;
List<AbstractInfos> infos = getItemInfos();
for (int i = 0; i < infos.size(); i++) {
int delta = col;
AbstractInfos info = infos.get(i);
if (info instanceof ItemInfos) {
ItemInfos item = (ItemInfos) info;
if (exportConfig.isResponseCols() || exportConfig.isPointCol() || exportConfig.isTimeCols() || exportConfig.isCommentCol()) {
List<Interaction> interactions = item.getInteractions();
for (int j = 0; j < interactions.size(); j++) {
Interaction interaction = interactions.get(j);
col = interactionArchiveMap.get(interaction.getQtiClassName()).writeHeader1(item.getAssessmentItem(), interaction, i, j, header1Row, col, workbook);
}
}
if (!exportConfig.isResponseCols()) {
col -= col - delta;
}
if (exportConfig.isPointCol()) {
col++;
}
if (exportConfig.isCommentCol()) {
col++;
}
if (exportConfig.isTimeCols()) {
col += anonymizerCallback != null ? 1 : 2;
}
} else if (numOfSections > 1 && info instanceof SectionInfos) {
SectionInfos section = (SectionInfos) info;
if (!section.getItemInfos().isEmpty()) {
String sectionTitle = translator.translate("archive.table.header.section", new String[] { section.getAssessmentSection().getTitle() });
header1Row.addCell(col++, sectionTitle, headerStyle);
}
}
}
}
Aggregations