From f7ef7136ab18af5d913f23185dacacf9e1800384 Mon Sep 17 00:00:00 2001 From: satomichan Date: Fri, 25 Jun 2021 08:58:36 +0900 Subject: [PATCH] =?utf8?q?=E3=82=BD=E3=83=BC=E3=82=B9=E7=AE=A1=E7=90=86?= =?utf8?q?=E3=81=AB=E8=BF=BD=E5=8A=A0=EF=BC=88=E4=BB=8A=E3=81=BE=E3=81=A7?= =?utf8?q?=E6=BC=8F=E3=82=8C=E3=81=A6=E3=81=84=E3=81=9F=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nucalgen/MextStdFoodCompTable.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 nucalgen/src/main/java/jp/satomichan/nucalgen/MextStdFoodCompTable.java diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/MextStdFoodCompTable.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/MextStdFoodCompTable.java new file mode 100644 index 0000000..246f5c0 --- /dev/null +++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/MextStdFoodCompTable.java @@ -0,0 +1,119 @@ +package jp.satomichan.nucalgen; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.XMLConfiguration; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +public class MextStdFoodCompTable { + private String brightColoredVegetablesXmlFileName = ""; + private List brightColoredVegetableList = new ArrayList(); + + MextStdFoodCompTable(String brightColoredVegetablesXmlFileName_){ + this.brightColoredVegetablesXmlFileName = brightColoredVegetablesXmlFileName_; + + try { + XMLConfiguration config = new XMLConfiguration(this.brightColoredVegetablesXmlFileName); + List vegetableNames = config.getList("bright-colored-vegetable.name"); + for(Object vegeObj : vegetableNames) { + this.brightColoredVegetableList.add(vegeObj.toString()); + } + + } catch (ConfigurationException e) { + e.printStackTrace(); + } + } + + + + //変換 + void processInto(Workbook outputWorkbook) { + Sheet foodComposithonSheet = outputWorkbook.getSheetAt(0); + outputWorkbook.setSheetName(0, "成分表"); + + //「成分識別子」行 + Row idRow = foodComposithonSheet.getRow(11); + 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"); + + + //セル加工 + for(int compSheetRowIndex = 12; compSheetRowIndex <= 9999; compSheetRowIndex++) { + Row compRow = foodComposithonSheet.getRow(compSheetRowIndex); + if(compRow == null) { + break; + } + + int group = Integer.parseInt(compRow.getCell(1).toString()) / 1000; + + for (int cellCount = 1; cellCount <= 61; cellCount++) { + Cell thisCell = compRow.getCell(cellCount); + + String cellString = thisCell.toString(); + + cellString = cellString.replaceAll("\\(", ""); + cellString = cellString.replaceAll("\\)", ""); + cellString = cellString.replaceAll("-", "0"); + cellString = cellString.replaceAll("Tr", "0"); + + //セル値・書式 コピー + //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); + } + + + } //for cellCount + + + + //食品群(1~18)書き込み + compRow.createCell(62).setCellValue(group); + + //緑黄色野菜か? + 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); + } + } + + + } //for compSheetRowIndex + + + //元の表 削除 + for(int i = outputWorkbook.getNumberOfSheets() - 1; i > 0; i--) { + outputWorkbook.removeSheetAt(i); + } + } + + + +} -- 2.24.4