「日本食品標準成分表2020年版(八訂)」の「2021年2月3日修正」に対応(表形式に変更があった)。 JAR_2021-02-14_2043_BUILD
authorsatomichan <git.20200328@...>
Sun, 14 Feb 2021 12:03:24 +0000 (21:03 +0900)
committersatomichan <git.20200328@...>
Sun, 14 Feb 2021 12:03:24 +0000 (21:03 +0900)
src/main/java/jp/satomichan/nucalgen/MextStdFoodCompTable.java
src/main/java/jp/satomichan/nucalgen/Nucalgen.java

index ec6718833c3765974ded7283ff01fe8db574502c..246f5c01bba7a8b9e34fef378c57f3ef9e34a73d 100644 (file)
@@ -34,12 +34,11 @@ public class MextStdFoodCompTable {
 
        //変換
        void processInto(Workbook outputWorkbook) {
-               Sheet foodComposithonSheet = outputWorkbook.cloneSheet(0);
-               outputWorkbook.setSheetName(18, "成分表");
-               outputWorkbook.setSheetOrder("成分表", 0);
+               Sheet foodComposithonSheet = outputWorkbook.getSheetAt(0);
+               outputWorkbook.setSheetName(0, "成分表");
 
                //「成分識別子」行
-               Row idRow = foodComposithonSheet.getRow(10);
+               Row idRow = foodComposithonSheet.getRow(11);
                for(int i = 4; i <= 61; i++) {
                        Cell idCell = idRow.getCell(i);
                        idCell.setCellValue(idCell.toString().replaceAll(" ", ""));
@@ -47,76 +46,70 @@ public class MextStdFoodCompTable {
                idRow.createCell(62).setCellValue("GROUP");
                idRow.createCell(63).setCellValue("BRIGHT_COLORED_VEGETABLE");
 
-               int compSheetRowIndex = 11;
 
-               //18 の食品群ごとの処理
-               for(int group = 1; group <= 18; group++) {
-                       Sheet thisSheet = outputWorkbook.getSheetAt(group);
-
-                       int rowCount = 0;
-                       for (Row thisRow : thisSheet) {
-                               rowCount++;
-                               if(rowCount < 12) {continue;}
-
-                               Row compRow = foodComposithonSheet.createRow(compSheetRowIndex);
+               //セル加工
+               for(int compSheetRowIndex = 12; compSheetRowIndex <= 9999; compSheetRowIndex++) {
+                       Row compRow = foodComposithonSheet.getRow(compSheetRowIndex);
+                       if(compRow == null) {
+                               break;
+                       }
 
-                               for (int cellCount = 1; cellCount <= 61; cellCount++) {
-                                       Cell thisCell = thisRow.getCell(cellCount);
+                       int group = Integer.parseInt(compRow.getCell(1).toString()) / 1000;
 
-                                       String cellString = thisCell.toString();
+                       for (int cellCount = 1; cellCount <= 61; cellCount++) {
+                               Cell thisCell = compRow.getCell(cellCount);
 
-                                       cellString = cellString.replaceAll("\\(", "");
-                                       cellString = cellString.replaceAll("\\)", "");
-                                       cellString = cellString.replaceAll("-", "0");
-                                       cellString = cellString.replaceAll("Tr", "0");
+                               String cellString = thisCell.toString();
 
-                                       //セル値・書式 コピー
-                                       //Cell compCell = foodComposithonSheet.getRow(compSheetRowIndex).getCell(cellCount);
-                                       Cell compCell = compRow.createCell(cellCount);
-                                       compCell.setCellValue(cellString);
-                                       compCell.setCellStyle(thisCell.getCellStyle());
-                                       compCell.setCellType(thisCell.getCellTypeEnum());
+                               cellString = cellString.replaceAll("\\(", "");
+                               cellString = cellString.replaceAll("\\)", "");
+                               cellString = cellString.replaceAll("-", "0");
+                               cellString = cellString.replaceAll("Tr", "0");
 
-                                       if(cellString.matches("^[\\d\\.]+$")) {
-                                               compCell.setCellValue(Double.parseDouble(cellString));
-                                               CellStyle aCellStyle = compCell.getCellStyle();
-                                               aCellStyle.setDataFormat((short) 0);
-                                               compCell.setCellStyle(aCellStyle);
-                                       }
+                               //セル値・書式 コピー
+                               //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);
+                               }
 
-                               } //CELL
 
+                       } //for cellCount
 
 
-                               //食品群(1~18)書き込み
-                               compRow.createCell(62).setCellValue(group);
 
-                               //緑黄色野菜か?
-                               boolean isBrightColored = false;
-                               if(group == 6 && brightColoredVegetablesXmlFileName.length() > 0) {
-                                       String foodName = thisRow.getCell(3).getStringCellValue();
-                                       for(String aBright : this.brightColoredVegetableList) {
-                                               if(foodName.matches(".*" + aBright + ".*")) {
-                                                       isBrightColored = true;
-                                                       break;
-                                               }
-                                       }
+                       //食品群(1~18)書き込み
+                       compRow.createCell(62).setCellValue(group);
 
-                                       if(isBrightColored) {
-                                               compRow.createCell(63).setCellValue(1);
+                       //緑黄色野菜か?
+                       boolean isBrightColored = false;
+                       if(group == 6 && brightColoredVegetablesXmlFileName.length() > 0) {
+                               String foodName = compRow.getCell(3).getStringCellValue();
+                               for(String aBright : this.brightColoredVegetableList) {
+                                       if(foodName.matches(".*" + aBright + ".*")) {
+                                               isBrightColored = true;
+                                               break;
                                        }
                                }
 
+                               if(isBrightColored) {
+                                       compRow.createCell(63).setCellValue(1);
+                               }
+                       }
 
-                               compSheetRowIndex++;
 
-                       } //ROW
+               } //for compSheetRowIndex
 
-               } //GROUP
 
                //元の表 削除
-               for(int i = 18; i > 0; i--) {
+               for(int i = outputWorkbook.getNumberOfSheets() - 1; i > 0; i--) {
                        outputWorkbook.removeSheetAt(i);
                }
        }
index bb80aa3e9c1f0f236a804b3f28fe01af0c1e7d51..9eb18fcb5a579bdb36a2b4f0fcbff66ae3dfe5cb 100644 (file)
@@ -102,8 +102,9 @@ public class Nucalgen {
                        for(int i = rowIndex; i < lines + 3; i++,rowIndex++) {
                                Row thisRow = calcSheet.createRow(rowIndex);
 
+                               //「食品名」
                                thisRow.createCell(1).setCellStyle(csPool.getCellStyle("00000", false));
-                               thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",成分表!$B$12:$BL$2500,3,FALSE),\"\")");
+                               thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",成分表!$B$13:$BL$2500,3,FALSE),\"\")");
                                thisRow.createCell(3).setCellStyle(csPool.getCellStyle("", false));
 
                                colIndex = 4;
@@ -113,7 +114,7 @@ public class Nucalgen {
 
                                        String div100 = aColumn.isUseRawValue() ? "" :  "/ 100 * $D" + (rowIndex + 1);
 
-                                       thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + "," + aColumn.getTable() + "!$B$12:$BL$2500,MATCH(\"" + aColumn.getName() + "\"," + aColumn.getTable() + "!$B$11:$BL$11,0),FALSE) " + div100 + ",\"\")");
+                                       thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + "," + aColumn.getTable() + "!$B$13:$BL$2500,MATCH(\"" + aColumn.getName() + "\"," + aColumn.getTable() + "!$B$12:$BL$12,0),FALSE) " + div100 + ",\"\")");
                                        colIndex++;
 
                                        usedTableList.add(aColumn.getTable());