From: satomichan Date: Sat, 26 Dec 2020 16:18:20 +0000 (+0900) Subject: 2020-12-27_八訂対応 X-Git-Tag: JAR_2020-12-27_1930_BUILD~1^2 X-Git-Url: https://satomichan.jp/gitweb/?a=commitdiff_plain;h=8fe44681981d1f6a230fe176892898dd8d56d310;p=nucalgen 2020-12-27_八訂対応 --- diff --git a/src/main/java/jp/satomichan/nucalgen/MoeStdFoodCompTable.java b/src/main/java/jp/satomichan/nucalgen/MoeStdFoodCompTable.java index 9799937..1a39f2d 100644 --- a/src/main/java/jp/satomichan/nucalgen/MoeStdFoodCompTable.java +++ b/src/main/java/jp/satomichan/nucalgen/MoeStdFoodCompTable.java @@ -32,60 +32,95 @@ public class MoeStdFoodCompTable { - //「本表」変換 + //変換 void processInto(Workbook outputWorkbook) { - Sheet mainSheet = outputWorkbook.getSheet("本表"); - int rowCount = 0; - int lastCol = mainSheet.getRow(5).getLastCellNum(); - mainSheet.getRow(5).getCell(4).setCellValue("廃棄率"); - mainSheet.getRow(5).createCell(lastCol + 1).setCellValue("食品群"); - mainSheet.getRow(5).createCell(lastCol + 2).setCellValue("緑黄色野菜"); + Sheet foodComposithonSheet = outputWorkbook.cloneSheet(0); + outputWorkbook.setSheetName(18, "成分表"); + outputWorkbook.setSheetOrder("成分表", 0); + //Sheet foodComposithonSheet = outputWorkbook.createSheet("成分表"); + + //「成分識別子」行 + Row idRow = foodComposithonSheet.getRow(10); + for(int i = 4; i <= 61; i++) { + Cell idCell = idRow.getCell(i); + idCell.setCellValue(idCell.toString().replaceAll(" ", "")); + } + idRow.createCell(62).setCellValue("GROUP"); + idRow.createCell(63).setCellValue("BRIGHT_COLORED_VEGETABLE"); + int compSheetRowIndex = 11; - for (Row row : mainSheet) { - rowCount++; - if(rowCount < 8) {continue;} + //18 の食品群ごとの処理 + for(int group = 1; group <= 18; group++) { + Sheet thisSheet = outputWorkbook.getSheetAt(group); - for (Cell cell : row) { - String cellString = cell.toString(); + int rowCount = 0; + for (Row thisRow : thisSheet) { + rowCount++; + if(rowCount < 12) {continue;} - cellString = cellString.replaceAll("\\(", ""); - cellString = cellString.replaceAll("\\)", ""); - cellString = cellString.replaceAll("-", "0"); - cellString = cellString.replaceAll("Tr", "0"); + Row compRow = foodComposithonSheet.createRow(compSheetRowIndex); + for (int cellCount = 1; cellCount <= 61; cellCount++) { + Cell thisCell = thisRow.getCell(cellCount); - if(cellString.matches("^[\\d\\.]+$")) { - cell.setCellValue(Double.parseDouble(cellString)); - CellStyle aCellStyle = cell.getCellStyle(); - aCellStyle.setDataFormat((short) 0); - cell.setCellStyle(aCellStyle); - } + String cellString = thisCell.toString(); - } + cellString = cellString.replaceAll("\\(", ""); + cellString = cellString.replaceAll("\\)", ""); + cellString = cellString.replaceAll("-", "0"); + cellString = cellString.replaceAll("Tr", "0"); - int gun = (int) row.getCell(0).getNumericCellValue(); - row.createCell(lastCol + 1).setCellValue(gun); + //セル値・書式 コピー + //Cell compCell = foodComposithonSheet.getRow(compSheetRowIndex).getCell(cellCount); + Cell compCell = compRow.createCell(cellCount); + compCell.setCellValue(cellString); + compCell.setCellStyle(thisCell.getCellStyle()); + compCell.setCellType(thisCell.getCellTypeEnum()); + + if(cellString.matches("^[\\d\\.]+$")) { + compCell.setCellValue(Double.parseDouble(cellString)); + CellStyle aCellStyle = compCell.getCellStyle(); + aCellStyle.setDataFormat((short) 0); + compCell.setCellStyle(aCellStyle); + } - //緑黄色野菜 - if(brightColoredVegetablesXmlFileName.length() > 0) { - boolean isBrightColored = false; - String foodName = row.getCell(3).getStringCellValue(); - for(String aBright : this.brightColoredVegetableList) { - if(foodName.matches(aBright + ".*")) { - isBrightColored = true; - break; + } //CELL + + //食品群(1~18)書き込み + compRow.createCell(62).setCellValue(group); + + + //緑黄色野菜か? + if(brightColoredVegetablesXmlFileName.length() > 0) { + boolean isBrightColored = false; + String foodName = thisRow.getCell(3).getStringCellValue(); + for(String aBright : this.brightColoredVegetableList) { + if(foodName.matches(aBright + ".*")) { + isBrightColored = true; + break; + } } - } - if(isBrightColored) { - row.createCell(lastCol + 2).setCellValue(1); + if(isBrightColored) { + compRow.createCell(63).setCellValue(1); + } } - } - } + compSheetRowIndex++; + + } //ROW + + } //GROUP + //元の表 削除 + for(int i = 18; i > 0; i--) { + outputWorkbook.removeSheetAt(i); + } } + + + } diff --git a/src/main/java/jp/satomichan/nucalgen/Nucalgen.java b/src/main/java/jp/satomichan/nucalgen/Nucalgen.java index 8c79e05..a385604 100644 --- a/src/main/java/jp/satomichan/nucalgen/Nucalgen.java +++ b/src/main/java/jp/satomichan/nucalgen/Nucalgen.java @@ -54,14 +54,11 @@ public class Nucalgen { Workbook outputWorkbook = WorkbookFactory.create(new FileInputStream(moeStdFoodCompTableFileName)); if(cmd.hasOption("use-processed-table") == false) { - //「本表」変換 + //成分表 変換 MoeStdFoodCompTable moe = new MoeStdFoodCompTable(cmd.getOptionValue("bright-colored-vegetables-list")); moe.processInto(outputWorkbook); } - //「別表」削除 - outputWorkbook.removeSheetAt(1); - //「栄養価計算」シート生成 Sheet calcSheet = outputWorkbook.createSheet("栄養価計算"); @@ -101,7 +98,7 @@ public class Nucalgen { Row thisRow = calcSheet.createRow(rowIndex); thisRow.createCell(1).setCellStyle(csPool.getCellStyle("00000", false)); - thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",本表!$B$9:$BS$2199,3,FALSE),\"\")"); + thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",成分表!$B$12:$BL$2500,3,FALSE),\"\")"); thisRow.createCell(3).setCellStyle(csPool.getCellStyle("", false)); colIndex = 4; @@ -111,7 +108,7 @@ public class Nucalgen { String div100 = aColumn.isUseRawValue() ? "" : "/ 100 * $D" + (rowIndex + 1); - thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + ",本表!$B$9:$BS$2199,MATCH(\"" + aColumn.getName() + "\",本表!$B$6:$BS$6,0),FALSE) " + div100 + ",\"\")"); + thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + ",成分表!$B$12:$BL$2500,MATCH(\"" + aColumn.getName() + "\",成分表!$B$11:$BL$11,0),FALSE) " + div100 + ",\"\")"); colIndex++; }