Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix that col width is not written if other col props are set #73

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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