Skip to content

Commit

Permalink
FIX: java.lang.IllegalArgumentException: Invalid char (/) found at in…
Browse files Browse the repository at this point in the history
…dex (23) in sheet name
  • Loading branch information
mspasiano committed May 9, 2024
1 parent 3c04066 commit cbd72fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2582,7 +2582,7 @@ private List<PropertyDefinition<?>> createHeadApplicationAll(Session session, Fo
}

private HSSFSheet createSheet(HSSFWorkbook wb, String sheetName, List<String> head) {
HSSFSheet sheet = wb.createSheet(sheetName);
HSSFSheet sheet = wb.createSheet(HSSFUtil.getSheetNameValid(sheetName));
HSSFRow headRow = sheet.createRow(0);
headRow.setHeight((short) 500);
HSSFCellStyle headStyle = wb.createCellStyle();
Expand Down Expand Up @@ -3284,7 +3284,7 @@ private HSSFCell createCellNumeric(HSSFRow row, int index) {

protected HSSFWorkbook createHSSFWorkbook(List<String> head, String sheetName) {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(sheetName);
HSSFSheet sheet = wb.createSheet(HSSFUtil.getSheetNameValid(sheetName));
HSSFRow headRow = sheet.createRow(0);
headRow.setHeight((short) 500);
HSSFCellStyle headStyle = wb.createCellStyle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ public String exportSchedeValutazione(Session currentCMISSession, String idCall,
for (HSSFPictureData picture : workbook.getAllPictures()) {
pictureId = wb.addPicture(picture.getData(), picture.getFormat());
}
HSSFSheet newSheet = wb.createSheet(sheetName);
HSSFSheet newSheet = wb.createSheet(HSSFUtil.getSheetNameValid(sheetName));
HSSFPrintSetup ps = newSheet.getPrintSetup();
ps.setLandscape(false);
HSSFUtil.copySheets(newSheet, workbook.getSheetAt(0), styleMap, pictureId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import org.apache.poi.ss.util.CellRangeAddress;

import java.util.Map;

import java.util.regex.Pattern;

/**
*
* @author jk
Expand Down Expand Up @@ -119,5 +120,15 @@ public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSS
break;
}

}
}

public static void main(String[] args) {
System.out.println(getSheetNameValid("Bando IEOS n. BR 18/2024"));
}

public static String getSheetNameValid(String sheetName) {
final Pattern pattern = Pattern.compile("[^A-Za-z0-9]", Pattern.CASE_INSENSITIVE);
return pattern.matcher(sheetName).replaceAll("-");
}

}

0 comments on commit cbd72fa

Please sign in to comment.