Skip to content

Commit

Permalink
Merge pull request #154 from rzymek/issue153
Browse files Browse the repository at this point in the history
Fixes: mutiple <definedNames> entries when multiple sheets
  • Loading branch information
Olivier Chédru authored Mar 23, 2021
2 parents 47ff169 + 1e4c5ec commit 1391729
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fastexcel-writer/src/main/java/org/dhatim/fastexcel/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ class Font {
* @param underlined Underlined flag.
* @param name Font name. Defaults to "Calibri".
* @param size Font size, in points. Defaults to 11.0.
* @param rgbColor RGB font color. Defaults to "000000".
* @param rgbColor RGB font color. Defaults to "FF000000".
* @return New font object.
*/
static Font build(boolean bold, boolean italic, boolean underlined, String name, BigDecimal size, String rgbColor) {
return new Font(bold, italic, underlined, name == null ? "Calibri" : name, size == null ? BigDecimal.valueOf(11.0) : size, rgbColor == null ? "000000" : rgbColor);
return new Font(bold, italic, underlined, name == null ? "Calibri" : name, size == null ? BigDecimal.valueOf(11.0) : size, rgbColor == null ? "FF000000" : rgbColor);
}

@Override
Expand Down
20 changes: 10 additions & 10 deletions fastexcel-writer/src/main/java/org/dhatim/fastexcel/Workbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,19 @@ private void writeWorkbookFile() throws IOException {
/** Defining repeating rows and columns for the print setup...
* This is defined for each sheet separately
* (if there are any repeating rows or cols in the sheet at all) **/


w.append("<definedNames>");
for (Worksheet ws : worksheets) {
int worksheetIndex = getIndex(ws) - 1;
int worksheetIndex = getIndex(ws) - 1;
String defineName = Stream.of(ws.getRepeatingCols(),ws.getRepeatingRows())
.filter(Objects::nonNull)
.map(r -> "&apos;" + ws.getName() + "&apos;!" + r.toString())
.collect(Collectors.joining(","));

w.append("<definedNames>");

if (!defineName.isEmpty()) {
w.append("<definedName function=\"false\" " +
"hidden=\"false\" localSheetId=\"" +
worksheetIndex + "\" name=\"_xlnm.Print_Titles\" " +
w.append("<definedName function=\"false\" " +
"hidden=\"false\" localSheetId=\"" +
worksheetIndex + "\" name=\"_xlnm.Print_Titles\" " +
"vbProcedure=\"false\">")
.append(defineName)
.append("</definedName>");
Expand All @@ -224,8 +224,8 @@ private void writeWorkbookFile() throws IOException {
for (Map.Entry<String, Range> nr : ws.getNamedRanges().entrySet()) {
String rangeName = nr.getKey();
Range range = nr.getValue();
w.append("<definedName function=\"false\" " +
"hidden=\"false\" localSheetId=\"" +
w.append("<definedName function=\"false\" " +
"hidden=\"false\" localSheetId=\"" +
worksheetIndex + "\" name=\"")
.append(rangeName)
.append("\" vbProcedure=\"false\">&apos;")
Expand All @@ -251,8 +251,8 @@ private void writeWorkbookFile() throws IOException {
.append("$" + Range.colToString(af.getRight()) + "$" + (1 + af.getBottom()))
.append("</definedName>");
}
w.append("</definedNames>");
}
w.append("</definedNames>");
w.append("</workbook>");
});
}
Expand Down

0 comments on commit 1391729

Please sign in to comment.