fix bug with sheetnames generating spreadsheets

This commit is contained in:
Grahame Grieve 2021-10-08 08:05:20 +11:00
parent a75ac22c91
commit db2004abb7
2 changed files with 23 additions and 3 deletions

View File

@ -84,7 +84,7 @@ public class SpreadsheetGenerator {
if (name.length() > MAX_SENSITIVE_SHEET_NAME_LEN - 2) { if (name.length() > MAX_SENSITIVE_SHEET_NAME_LEN - 2) {
name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN - 2); name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN - 2);
} }
String s = name; String s = fixSheetNameChars(name);
if (sheetNames.contains(s)) { if (sheetNames.contains(s)) {
int i = 1; int i = 1;
do { do {
@ -96,6 +96,26 @@ public class SpreadsheetGenerator {
return wb.createSheet(s); return wb.createSheet(s);
} }
private String fixSheetNameChars(String name) {
StringBuilder b = new StringBuilder();
for (char ch : name.toCharArray()) {
switch (ch) {
case '/':
case '\\':
case '?':
case '*':
case ']':
case '[':
case ':':
b.append('_');
break;
default:
b.append(ch);
}
}
return b.toString();
}
private static Map<String, CellStyle> createStyles(Workbook wb){ private static Map<String, CellStyle> createStyles(Workbook wb){
Map<String, CellStyle> styles = new HashMap<>(); Map<String, CellStyle> styles = new HashMap<>();

View File

@ -82,9 +82,9 @@ public class StructureDefinitionSpreadsheetGenerator extends CanonicalSpreadshee
"Slicing Discriminator", "Slicing Description", "Slicing Ordered", "Slicing Rules", "Base Path", "Base Min", "Base Max", "Slicing Discriminator", "Slicing Description", "Slicing Ordered", "Slicing Rules", "Base Path", "Base Min", "Base Max",
"Condition(s)", "Constraint(s)"}; "Condition(s)", "Constraint(s)"};
public StructureDefinitionSpreadsheetGenerator(IWorkerContext context, boolean asXml, boolean hideMustSupportFalse) { public StructureDefinitionSpreadsheetGenerator(IWorkerContext context, boolean valuesAsXml, boolean hideMustSupportFalse) {
super(context); super(context);
this.asXml = asXml; this.asXml = valuesAsXml;
this.hideMustSupportFalse = hideMustSupportFalse; this.hideMustSupportFalse = hideMustSupportFalse;
} }