2020-12-27_八訂対応
[nucalgen] / src / main / java / jp / satomichan / nucalgen / MoeStdFoodCompTable.java
index 9799937144b3f4feb506de5e2cc00766aab2d699..1a39f2dcc36bc72ecb3b1ca2381f1df0f1e16753 100644 (file)
@@ -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);
+               }
        }
+
+
+
 }