Skip to content

Commit f803715

Browse files
authored
Merge pull request #447 from meiMingle/fix_issue_445
Fix issue #445
2 parents 92d8cfe + 3e438e3 commit f803715

File tree

1 file changed

+16
-14
lines changed
  • fastexcel-writer/src/main/java/org/dhatim/fastexcel

1 file changed

+16
-14
lines changed

fastexcel-writer/src/main/java/org/dhatim/fastexcel/Table.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import java.io.IOException;
44

5-
public class Table{
5+
public class Table {
66
int index;
7-
private String name ;
7+
private String name;
88
private String displayName;
99
private boolean totalsRowShown = false;
10-
private Range range;
11-
private String[] headers ;
10+
private final Range range;
11+
private final String[] headers;
1212

1313
private final TableStyleInfo styleInfo = new TableStyleInfo(this);
1414

@@ -46,10 +46,12 @@ public TableStyleInfo styleInfo() {
4646

4747
public class TableStyleInfo {
4848
private final Table table;
49-
TableStyleInfo(Table table){
49+
50+
TableStyleInfo(Table table) {
5051
this.table = table;
5152
}
52-
private String name ;
53+
54+
private String name;
5355
private boolean showFirstColumn = false;
5456
private boolean showLastColumn = false;
5557
private boolean showRowStripes = true;
@@ -81,11 +83,11 @@ public TableStyleInfo setShowColumnStripes(boolean showColumnStripes) {
8183
}
8284

8385
public void write(Writer w) throws IOException {
84-
w.append("<tableStyleInfo name=\""+(name==null||"".equals(name)?"TableStyleMedium2":styleInfo.name)+"\" ");
85-
w.append("showFirstColumn=\""+(showFirstColumn?1:0)+"\" ");
86-
w.append("showLastColumn=\""+(showLastColumn?1:0)+"\" ");
87-
w.append("showRowStripes=\""+(showRowStripes?1:0)+"\" ");
88-
w.append("showColumnStripes=\""+(showColumnStripes?1:0)+"\"/>");
86+
w.append("<tableStyleInfo name=\"" + (name == null || "".equals(name) ? "TableStyleMedium2" : styleInfo.name) + "\" ");
87+
w.append("showFirstColumn=\"" + (showFirstColumn ? 1 : 0) + "\" ");
88+
w.append("showLastColumn=\"" + (showLastColumn ? 1 : 0) + "\" ");
89+
w.append("showRowStripes=\"" + (showRowStripes ? 1 : 0) + "\" ");
90+
w.append("showColumnStripes=\"" + (showColumnStripes ? 1 : 0) + "\"/>");
8991
w.append("</table>");
9092
}
9193
}
@@ -94,15 +96,15 @@ void write(Writer w) throws IOException {
9496
w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
9597
w.append("<table xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" ");
9698
w.append("id=\"" + index + "\" ");
97-
w.append("name=\""+(name==null||"".equals(name)?"Table"+index:name)+"\" ");
98-
w.append("displayName=\"" + (displayName==null||"".equals(displayName)?"Table"+index:displayName) + "\" ");
99+
w.append("name=\"" + (name == null || name.isEmpty() ? "Table" + index : XmlEscapeHelper.escape(name)) + "\" ");
100+
w.append("displayName=\"" + (displayName == null || displayName.isEmpty() ? "Table" + index : XmlEscapeHelper.escape(displayName)) + "\" ");
99101
w.append("ref=\"" + range.toString() + "\" ");
100102
w.append("totalsRowShown=\"" + (totalsRowShown ? 1 : 0) + "\">");
101103
w.append("<autoFilter ref=\"" + range.toString() + "\"/>");
102104
int count = range.getRight() - range.getLeft() + 1;
103105
w.append("<tableColumns count=\"" + count + "\">");
104106
for (int i = 0; i < count; i++) {
105-
w.append("<tableColumn id=\"" + (i + 1) + "\" name=\"" + headers[i] + "\"/>");
107+
w.append("<tableColumn id=\"" + (i + 1) + "\" name=\"" + XmlEscapeHelper.escape(headers[i]) + "\"/>");
106108
}
107109
w.append("</tableColumns>");
108110
styleInfo.write(w);

0 commit comments

Comments
 (0)