Skip to content

Commit

Permalink
Merge pull request #73 from LoadingByte/mixing-col-props
Browse files Browse the repository at this point in the history
Fix that col width is not written if other col props are set
  • Loading branch information
miachm authored Jul 17, 2023
2 parents d6437c9 + 611b4cf commit b21e221
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/com/github/miachm/sods/OdsWritter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class OdsWritter {
private SpreadSheet spread;
private Compressor out;
private Map<Style, String> stylesUsed = new HashMap<>();
private Map<ColumnStyle, String> columnStyleStringMap = new HashMap<>();
private Map<RowStyle, String> rowStyleStringMap = new HashMap<>();
private Map<Double, String> columnStyleStringMap = new HashMap<>();
private Map<Double, String> rowStyleStringMap = new HashMap<>();
private Map<TableStyle, String> tableStyleStringMap = new HashMap<>();
private final String MIMETYPE= "application/vnd.oasis.opendocument.spreadsheet";

Expand Down Expand Up @@ -194,7 +194,7 @@ private void writeColumnsStyles(XMLStreamWriter out, Sheet sheet) throws XMLStre

Double width = column.column_style.getWidth();
if (width != null) {
String name = columnStyleStringMap.get(column.column_style);
String name = columnStyleStringMap.get(width);
if (name != null)
out.writeAttribute("table:style-name", name);
}
Expand Down Expand Up @@ -343,7 +343,7 @@ else if (Character.isHighSurrogate(text.charAt(i)) && i + 1 < text.length() && C
private void writeRowHeight(XMLStreamWriter out, Row row) throws XMLStreamException {
Double height = row.row_style.getHeight();
if (height != null) {
String name = rowStyleStringMap.get(row.row_style);
String name = rowStyleStringMap.get(height);
if (name != null)
out.writeAttribute("table:style-name", name);
}
Expand Down Expand Up @@ -517,9 +517,7 @@ private String toValue(Style.TEXT_ALIGMENT textAligment) {
}

private void writeColumnStyle(XMLStreamWriter out, Double width) throws XMLStreamException {
ColumnStyle columnStyle = new ColumnStyle();
columnStyle.setWidth(width);
if (!columnStyleStringMap.containsKey(columnStyle)) {
if (!columnStyleStringMap.containsKey(width)) {
String key = "co" + columnStyleStringMap.size();

out.writeStartElement("style:style");
Expand All @@ -530,14 +528,12 @@ private void writeColumnStyle(XMLStreamWriter out, Double width) throws XMLStrea
out.writeEndElement();
out.writeEndElement();

columnStyleStringMap.put(columnStyle, key);
columnStyleStringMap.put(width, key);
}
}

private void writeRowStyle(XMLStreamWriter out, Double height) throws XMLStreamException {
RowStyle rowStyle = new RowStyle();
rowStyle.setHeight(height);
if (!rowStyleStringMap.containsKey(rowStyle)) {
if (!rowStyleStringMap.containsKey(height)) {
String key = "ro" + rowStyleStringMap.size();
out.writeStartElement("style:style");
out.writeAttribute("style:family", "table-row");
Expand All @@ -547,7 +543,7 @@ private void writeRowStyle(XMLStreamWriter out, Double height) throws XMLStreamE
out.writeEndElement();
out.writeEndElement();

rowStyleStringMap.put(rowStyle, key);
rowStyleStringMap.put(height, key);
}
}

Expand Down

0 comments on commit b21e221

Please sign in to comment.