Skip to content

Commit

Permalink
Solved mostly correct Calc / ODS export row-height
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Diederich committed Feb 8, 2025
1 parent 9cba34a commit a543594
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.odftoolkit.odfdom.dom.element.config.ConfigConfigItemElement;
import org.odftoolkit.odfdom.dom.element.config.ConfigConfigItemMapEntryElement;
import org.odftoolkit.odfdom.dom.element.style.StyleParagraphPropertiesElement;
import org.odftoolkit.odfdom.dom.element.style.StyleStyleElement;
import org.odftoolkit.odfdom.dom.element.style.StyleTableCellPropertiesElement;
import org.odftoolkit.odfdom.dom.element.style.StyleTableRowPropertiesElement;
import org.odftoolkit.odfdom.dom.element.style.StyleTextPropertiesElement;
Expand Down Expand Up @@ -120,6 +121,8 @@ public class CalcFileWriter {
private static final String VALUE_TYPE_STRING = "string";
private static final String CONFIG_TYPE_SHORT = "short";

public static final String ROW_HEIGHT = "0.5cm";

private CalcFileWriter() {}

public static void write(
Expand Down Expand Up @@ -536,7 +539,7 @@ private static void writeData(
very hard to read.
*/
OdfStyle rowStyle = officeStyles.newStyle(ROW_STYLE, OdfStyleFamily.TableRow);
rowStyle.setProperty(StyleTableRowPropertiesElement.RowHeight, "20.001cm");
rowStyle.setProperty(StyleTableRowPropertiesElement.RowHeight, ROW_HEIGHT);

for (ProjectLicenseInfo projectInfo : projectLicenseInfos) {
final OdfStyle cellStyle, hyperlinkStyle;
Expand All @@ -555,10 +558,23 @@ private static void writeData(
int extraRows = 0;
OdfTableRow currentRow = table.appendRow();

// currentRow.setUseOptimalHeight(false);
// currentRow.setHeight(20, false);
currentRow.setUseOptimalHeight(false);
// currentRow.setHeight(10, false);
// currentRow.setDefaultCellStyle(rowStyle);
currentRow.getOdfElement().setStyleName(ROW_STYLE);

/*
For some buggy reasons OpenOffice Calc only respects the automatic styles for row-heights,
and ignores the row-specific styles.
But it respects the color styles for row-specific styles.
And the row heights must be set,
otherwise the documents become unreadable with large extracted licenses,
because the rows grow gargantuan high.
*/
StyleStyleElement styleElement = currentRow.getOdfElement().getOrCreateUnqiueAutomaticStyle();
styleElement.setProperty(StyleTableRowPropertiesElement.RowHeight, ROW_HEIGHT);

rowMap.put(currentRowIndex, currentRow);
// Plugin ID
createDataCellsInRow(
Expand Down

0 comments on commit a543594

Please sign in to comment.