Skip to content
Snippets Groups Projects
Commit b6522fd6 authored by srosse's avatar srosse
Browse files

OO-3542: add a style to align text vertical=top

parent a622dc64
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ import java.util.Date; ...@@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.media.MediaResource; import org.olat.core.gui.media.MediaResource;
import org.olat.core.gui.render.EmptyURLBuilder; import org.olat.core.gui.render.EmptyURLBuilder;
import org.olat.core.gui.render.StringOutput; import org.olat.core.gui.render.StringOutput;
...@@ -113,6 +114,8 @@ public class XlsFlexiTableExporter implements FlexiTableExporter { ...@@ -113,6 +114,8 @@ public class XlsFlexiTableExporter implements FlexiTableExporter {
dataRow.addCell(col, (Date)value, workbook.getStyles().getDateStyle()); dataRow.addCell(col, (Date)value, workbook.getStyles().getDateStyle());
} else if(value instanceof Number) { } else if(value instanceof Number) {
dataRow.addCell(col, (Number)value, null); dataRow.addCell(col, (Number)value, null);
} else if(value instanceof FormItem) {
// do nothing
} else { } else {
StringOutput so = StringOutputPool.allocStringBuilder(1000); StringOutput so = StringOutputPool.allocStringBuilder(1000);
cd.getCellRenderer().render(null, so, value, row, ftC, ubu, translator); cd.getCellRenderer().render(null, so, value, row, ftC, ubu, translator);
...@@ -123,7 +126,7 @@ public class XlsFlexiTableExporter implements FlexiTableExporter { ...@@ -123,7 +126,7 @@ public class XlsFlexiTableExporter implements FlexiTableExporter {
if(StringHelper.containsNonWhitespace(cellValue)) { if(StringHelper.containsNonWhitespace(cellValue)) {
cellValue = StringEscapeUtils.unescapeHtml(cellValue); cellValue = StringEscapeUtils.unescapeHtml(cellValue);
} }
dataRow.addCell(col, cellValue, null); dataRow.addCell(col, cellValue, workbook.getStyles().getTopAlignStyle());
} }
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -702,10 +702,24 @@ public class OpenXMLWorkbook implements Closeable { ...@@ -702,10 +702,24 @@ public class OpenXMLWorkbook implements Closeable {
if(style.getFill().getIndex() > 0) { if(style.getFill().getIndex() > 0) {
writer.writeAttribute("applyFill", "1"); writer.writeAttribute("applyFill", "1");
} }
if(StringHelper.containsNonWhitespace(style.getApplyNumberFormat())) { if(StringHelper.containsNonWhitespace(style.getApplyNumberFormat())) {
writer.writeAttribute("applyNumberFormat", style.getApplyNumberFormat()); writer.writeAttribute("applyNumberFormat", style.getApplyNumberFormat());
} }
if(StringHelper.containsNonWhitespace(style.getApplyAlignment())) {
writer.writeAttribute("applyalignment", style.getApplyAlignment());
}
if(style.getAlignment() != null) {
writer.writeStartElement("alignment");
if(StringHelper.containsNonWhitespace(style.getAlignment().getVertical())) {
writer.writeAttribute("vertical", style.getAlignment().getVertical());
}
if(StringHelper.containsNonWhitespace(style.getAlignment().getWraptext())) {
writer.writeAttribute("wraptext", style.getAlignment().getWraptext());
}
writer.writeEndElement();
}
writer.writeEndElement(); writer.writeEndElement();
} }
......
...@@ -22,6 +22,7 @@ package org.olat.core.util.openxml; ...@@ -22,6 +22,7 @@ package org.olat.core.util.openxml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.olat.core.util.openxml.workbookstyle.Alignment;
import org.olat.core.util.openxml.workbookstyle.Border; import org.olat.core.util.openxml.workbookstyle.Border;
import org.olat.core.util.openxml.workbookstyle.CellStyle; import org.olat.core.util.openxml.workbookstyle.CellStyle;
import org.olat.core.util.openxml.workbookstyle.Fill; import org.olat.core.util.openxml.workbookstyle.Fill;
...@@ -63,6 +64,7 @@ public class OpenXMLWorkbookStyles { ...@@ -63,6 +64,7 @@ public class OpenXMLWorkbookStyles {
private final CellStyle correctStyle; private final CellStyle correctStyle;
private final CellStyle percentStyle; private final CellStyle percentStyle;
private final CellStyle lightGrayStyle; private final CellStyle lightGrayStyle;
private final CellStyle topAlignStyle;
public OpenXMLWorkbookStyles() { public OpenXMLWorkbookStyles() {
standardFont = new Font(fonts.size(), "12", "1", "Calibri", "2", "minor", FontStyle.none); standardFont = new Font(fonts.size(), "12", "1", "Calibri", "2", "minor", FontStyle.none);
...@@ -84,24 +86,27 @@ public class OpenXMLWorkbookStyles { ...@@ -84,24 +86,27 @@ public class OpenXMLWorkbookStyles {
borderRight = new Border(borders.size(), "thin", null, null, null); borderRight = new Border(borders.size(), "thin", null, null, null);
borders.add(borderRight); borders.add(borderRight);
standardStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null); standardStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null, null, null);
cellXfs.add(standardStyle); cellXfs.add(standardStyle);
borderRightStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, borderRight, null, null); borderRightStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, borderRight, null, null, null, null);
cellXfs.add(borderRightStyle); cellXfs.add(borderRightStyle);
dateStyle = new CellStyle(cellXfs.size(), DATE_FORMAT, standardFont, noneFile, noBorder, null, "1"); dateStyle = new CellStyle(cellXfs.size(), DATE_FORMAT, standardFont, noneFile, noBorder, null, "1", null, null);
cellXfs.add(dateStyle); cellXfs.add(dateStyle);
dateTimeStyle = new CellStyle(cellXfs.size(), DATE_TIME_FORMAT, standardFont, noneFile, noBorder, null, "1"); dateTimeStyle = new CellStyle(cellXfs.size(), DATE_TIME_FORMAT, standardFont, noneFile, noBorder, null, "1", null, null);
cellXfs.add(dateTimeStyle); cellXfs.add(dateTimeStyle);
durationStyle = new CellStyle(cellXfs.size(), TIME_FORMAT, standardFont, noneFile, borderRight, null, "1"); durationStyle = new CellStyle(cellXfs.size(), TIME_FORMAT, standardFont, noneFile, borderRight, null, "1", null, null);
cellXfs.add(durationStyle); cellXfs.add(durationStyle);
headerStyle = new CellStyle(cellXfs.size(), "0", boldFont, noneFile, noBorder, null, null); headerStyle = new CellStyle(cellXfs.size(), "0", boldFont, noneFile, noBorder, null, null, null, null);
cellXfs.add(headerStyle); cellXfs.add(headerStyle);
correctStyle = new CellStyle(cellXfs.size(), "0", boldFont, correctFill, noBorder, null, null); correctStyle = new CellStyle(cellXfs.size(), "0", boldFont, correctFill, noBorder, null, null, null, null);
cellXfs.add(correctStyle); cellXfs.add(correctStyle);
percentStyle = new CellStyle(cellXfs.size(), PERCENT_FORMAT, standardFont, noneFile, borderRight, null, "1"); percentStyle = new CellStyle(cellXfs.size(), PERCENT_FORMAT, standardFont, noneFile, borderRight, null, "1", null, null);
cellXfs.add(percentStyle); cellXfs.add(percentStyle);
lightGrayStyle = new CellStyle(cellXfs.size(), "0", standardFont, lightGrayFill, borderRight, null, null); lightGrayStyle = new CellStyle(cellXfs.size(), "0", standardFont, lightGrayFill, borderRight, null, null, null, null);
cellXfs.add(lightGrayStyle); cellXfs.add(lightGrayStyle);
Alignment topAlign = new Alignment(Alignment.TOP, "1");
topAlignStyle = new CellStyle(cellXfs.size(), "0", standardFont, noneFile, noBorder, null, null, topAlign, "1");
cellXfs.add(topAlignStyle);
} }
public CellStyle getBorderRightStyle() { public CellStyle getBorderRightStyle() {
...@@ -144,6 +149,10 @@ public class OpenXMLWorkbookStyles { ...@@ -144,6 +149,10 @@ public class OpenXMLWorkbookStyles {
return lightGrayStyle; return lightGrayStyle;
} }
public CellStyle getTopAlignStyle() {
return topAlignStyle;
}
public List<Font> getFonts() { public List<Font> getFonts() {
return fonts; return fonts;
} }
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.util.openxml.workbookstyle;
/**
*
* Initial date: 20 juin 2018<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class Alignment {
public static final String TOP = "top";
private final String vertical;
private final String wraptext;
public Alignment(String vertical, String wraptext) {
this.vertical = vertical;
this.wraptext = wraptext;
}
public String getVertical() {
return vertical;
}
public String getWraptext() {
return wraptext;
}
}
...@@ -35,13 +35,14 @@ public class CellStyle extends IndexedObject { ...@@ -35,13 +35,14 @@ public class CellStyle extends IndexedObject {
private Border border; private Border border;
private String applyBorder; private String applyBorder;
private String applyNumberFormat; private String applyNumberFormat;
private Alignment alignment;
private String applyAlignment;
public CellStyle(int index) { public CellStyle(int index) {
super(index); super(index);
} }
public CellStyle(int index, String numFmtId, Font font, Fill fill, Border border, String applyBorder, String applyNumberFormat) { public CellStyle(int index, String numFmtId, Font font, Fill fill, Border border, String applyBorder, String applyNumberFormat, Alignment alignment, String applyAlignment) {
super(index); super(index);
this.numFmtId = numFmtId; this.numFmtId = numFmtId;
this.font = font; this.font = font;
...@@ -49,6 +50,8 @@ public class CellStyle extends IndexedObject { ...@@ -49,6 +50,8 @@ public class CellStyle extends IndexedObject {
this.border = border; this.border = border;
this.applyBorder = applyBorder; this.applyBorder = applyBorder;
this.applyNumberFormat = applyNumberFormat; this.applyNumberFormat = applyNumberFormat;
this.applyAlignment = applyAlignment;
this.alignment = alignment;
} }
public Font getFont() { public Font getFont() {
...@@ -106,4 +109,20 @@ public class CellStyle extends IndexedObject { ...@@ -106,4 +109,20 @@ public class CellStyle extends IndexedObject {
public void setApplyNumberFormat(String applyNumberFormat) { public void setApplyNumberFormat(String applyNumberFormat) {
this.applyNumberFormat = applyNumberFormat; this.applyNumberFormat = applyNumberFormat;
} }
public String getApplyAlignment() {
return applyAlignment;
}
public void setApplyAlignment(String applyAlignment) {
this.applyAlignment = applyAlignment;
}
public Alignment getAlignment() {
return alignment;
}
public void setAlignment(Alignment alignment) {
this.alignment = alignment;
}
} }
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.curriculum.model; package org.olat.modules.curriculum.model;
import org.olat.basesecurity.GroupMembershipInheritance; import org.olat.basesecurity.GroupMembershipInheritance;
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.curriculum.ui; package org.olat.modules.curriculum.ui;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment