From c2f0b211cf04a0747e66dbd8ad7cb5a265f572e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Dervaux?= <stephane.dervaux@inrae.fr> Date: Thu, 7 Mar 2024 10:28:17 +0100 Subject: [PATCH] remove non alphanum char from excel sheet name --- .../po2vocabmanager/utils/DataTreeCell.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java index 34fbd496..e0199e72 100644 --- a/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java +++ b/src/main/java/fr/inra/po2vocabmanager/utils/DataTreeCell.java @@ -612,7 +612,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { Task<Boolean> taskExport = new Task<Boolean>() { @Override protected Boolean call() throws Exception { - XSSFSheet sheet = book.createSheet("obs|"+file.getNameProperty().getValue()); + XSSFSheet sheet = book.createSheet("obs|"+Tools.removeNonAlphaNumChar(file.getNameProperty().getValue())); Integer compteur = 0; Integer maxColumn = 0; @@ -631,7 +631,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { JSONObject hierarchyVocab = mainApp.getOntologyControler().getHierarchyVocabJSON(); // Récupération de l'ontology au format JSON - XSSFSheet sheetOntoVocab = book.createSheet("onto-vocab|" + mainApp.getOntologyControler().getCurrentOntology().getName().getValue()); + XSSFSheet sheetOntoVocab = book.createSheet("onto-vocab|" + Tools.removeNonAlphaNumChar(mainApp.getOntologyControler().getCurrentOntology().getName().getValue())); JSONArray vocab = (JSONArray) hierarchyVocab.get("vocabulary"); compteur = 0; @@ -648,7 +648,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { Tools.autoResize(sheetOntoVocab, maxColumn); - XSSFSheet sheetOntohierarchy = book.createSheet("onto-hierarchy|" + mainApp.getOntologyControler().getCurrentOntology().getName().getValue()); + XSSFSheet sheetOntohierarchy = book.createSheet("onto-hierarchy|" + Tools.removeNonAlphaNumChar(mainApp.getOntologyControler().getCurrentOntology().getName().getValue())); JSONArray hierarchy = (JSONArray) hierarchyVocab.get("hierarchy"); compteur = 0; @@ -880,14 +880,6 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { bok.setOnAction(actionEvent -> { if(rbNew.isSelected()) { -// String unique = "" + Tools.generateUniqueTimeStamp(); -// String fileName = "composition_" + unique; -// String fileNameConduite = "conduite_" + unique; -// String stepName = Normalizer.normalize(s.getName(), Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); -// String filePath = Paths.get(s.getGeneralFile().getFilePath()).getParent().toAbsolutePath().toString() + File.separator+ stepName + File.separator+ "composition-conduite"+ File.separator + fileName + ".xlsx"; -// String filePathConduite = Paths.get(s.getGeneralFile().getFilePath()).getParent().toAbsolutePath().toString() + File.separator + stepName + File.separator+ "composition-conduite"+ File.separator + fileNameConduite + ".xlsx"; - - CompositionFile compo = new CompositionFile(s, comboType.getValue().equalsIgnoreCase("input") ? true : false); compo.setCompositionID(textNew.getText()); } else { @@ -956,7 +948,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { // composition for (Map.Entry<CompositionFile, Boolean> entry : s.getCompositionFile().entrySet()) { - XSSFSheet sheetCompo = book.createSheet("compo-"+(entry.getValue() ? "input" : "output")+"|"+entry.getKey().getCompositionID().getValue().get()); + XSSFSheet sheetCompo = book.createSheet("compo-"+(entry.getValue() ? "input" : "output")+"|"+Tools.removeNonAlphaNumChar(entry.getKey().getCompositionID().getValue().get())); Integer compteurCompo = 0; Integer maxColumnCompo = 0; for (LinkedList<String> line : entry.getKey().getDataForExcel()) { @@ -975,7 +967,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { Tools.autoResize(sheet, maxColumn); for(ObservationFile obs : s.getObservationFiles()) { - XSSFSheet sheetObs = book.createSheet("obs|"+obs.getCID().getValue().get()); + XSSFSheet sheetObs = book.createSheet("obs|"+Tools.removeNonAlphaNumChar(obs.getCID().getValue().get())); Integer compteurObs = 0; Integer maxColumnObs = 0; @@ -994,7 +986,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { JSONObject hierarchyVocab = mainApp.getOntologyControler().getHierarchyVocabJSON(); // Récupération de l'ontology au format JSON - XSSFSheet sheetOntoVocab = book.createSheet("onto-vocab|" + mainApp.getOntologyControler().getCurrentOntology().getName().getValue()); + XSSFSheet sheetOntoVocab = book.createSheet("onto-vocab|" + Tools.removeNonAlphaNumChar(mainApp.getOntologyControler().getCurrentOntology().getName().getValue())); JSONArray vocab = (JSONArray) hierarchyVocab.get("vocabulary"); compteur = 0; @@ -1010,7 +1002,7 @@ public class DataTreeCell extends TextFieldTreeCell<DataNode> { Tools.autoResize(sheetOntoVocab, maxColumn); - XSSFSheet sheetOntohierarchy = book.createSheet("onto-hierarchy|" + mainApp.getOntologyControler().getCurrentOntology().getName().getValue()); + XSSFSheet sheetOntohierarchy = book.createSheet("onto-hierarchy|" + Tools.removeNonAlphaNumChar(mainApp.getOntologyControler().getCurrentOntology().getName().getValue())); JSONArray hierarchy = (JSONArray) hierarchyVocab.get("hierarchy"); compteur = 0; -- GitLab