From: satomichan Date: Sat, 26 Jun 2021 05:37:50 +0000 (+0900) Subject: 「付加行」機能 実装(いちおう)完了。 X-Git-Tag: JAR_2021-06-26_2349_BUILD~1 X-Git-Url: https://satomichan.jp/gitweb/?a=commitdiff_plain;h=5ead7185b8b04d74757dd3a9b07caf0f9eca4e63;p=nucalgen 「付加行」機能 実装(いちおう)完了。 「食品群別摂取量」部分を、プログラムから設定ファイルに分離した。 --- diff --git a/nucalgen/group-sum.xml b/nucalgen/group-sum.xml new file mode 100644 index 0000000..87db1cc --- /dev/null +++ b/nucalgen/group-sum.xml @@ -0,0 +1,34 @@ + + + + + 食品群別摂取量 + + + + 食品群 + + 摂取量(g) + + + 1穀類SUMIF(AREA_GROUP, 1, AREA_INTAKE) + 2いも及びでん粉類SUMIF(AREA_GROUP, 2, AREA_INTAKE) + 3砂糖及び甘味類SUMIF(AREA_GROUP, 3, AREA_INTAKE) + 4豆類SUMIF(AREA_GROUP, 4, AREA_INTAKE) + 5種実類SUMIF(AREA_GROUP, 5, AREA_INTAKE) + 6野菜類SUMIF(AREA_GROUP, 6, AREA_INTAKE) + うち 緑黄色野菜SUMIF(AREA_BRIGHT_COLORED_VEGETABLE, 1, AREA_INTAKE) + 7果実類SUMIF(AREA_GROUP, 7, AREA_INTAKE) + 8きのこ類SUMIF(AREA_GROUP, 8, AREA_INTAKE) + 9藻類SUMIF(AREA_GROUP, 9, AREA_INTAKE) + 10魚介類SUMIF(AREA_GROUP, 10, AREA_INTAKE) + 11肉類SUMIF(AREA_GROUP, 11, AREA_INTAKE) + 12卵類SUMIF(AREA_GROUP, 12, AREA_INTAKE) + 13乳類SUMIF(AREA_GROUP, 13, AREA_INTAKE) + 14油脂類SUMIF(AREA_GROUP, 14, AREA_INTAKE) + 15菓子類SUMIF(AREA_GROUP, 15, AREA_INTAKE) + 16し好飲料類SUMIF(AREA_GROUP, 16, AREA_INTAKE) + 17調味料及び香辛料類SUMIF(AREA_GROUP, 17, AREA_INTAKE) + 18調理加工食品類SUMIF(AREA_GROUP, 18, AREA_INTAKE) + + diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java index b6065c9..2cf039e 100644 --- a/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java +++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java @@ -4,7 +4,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,7 +24,6 @@ import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import jp.satomichan.nucalgen.addition.AcCell; -import jp.satomichan.nucalgen.addition.AcCellType; import jp.satomichan.nucalgen.addition.AcRow; import jp.satomichan.nucalgen.addition.AdditionConfig; import jp.satomichan.nucalgen.addition.AdditionUtil; @@ -41,8 +39,6 @@ public class Nucalgen { options.addOption(Option.builder("o").required().hasArg().longOpt("output").build()); options.addOption(Option.builder("l").required().hasArg().longOpt("lines").build()); options.addOption(Option.builder("add").hasArgs().longOpt("addition").build()); - - options.addOption(Option.builder("groupsum").longOpt("with-group-sum").build()); options.addOption(Option.builder("bright").hasArg().longOpt("bright-colored-vegetables-list").build()); options.addOption(Option.builder("protect").longOpt("set-protect").build()); options.addOption(Option.builder("processed").longOpt("use-processed-table").build()); @@ -164,7 +160,6 @@ public class Nucalgen { if(aColumn.isUseSum()) { String sumArea = new CellReference(rowIndex, colIndex, true, true).formatAsString(); namedAreaMap.put("SUM_" + aColumn.getAlias(), sumArea); - //System.out.println("SUM_" + aColumn.getAlias() + " --- " + sumArea); } } @@ -185,12 +180,6 @@ public class Nucalgen { } } - //「食品群別摂取量」出力 - if(cmd.hasOption("with-group-sum")) { - rowIndex += 3; - rowIndex = generateGroupSum(calcSheet, csPool, rowIndex, namedAreaMap); - } - //未使用表シート削除 for(int si = outputWorkbook.getNumberOfSheets() - 1 ; si >= 1 ; si--) { @@ -221,52 +210,12 @@ public class Nucalgen { } - //群別摂取量 - private static int generateGroupSum(Sheet calcSheet, CellStylePool csPool, int rowIndex, Map _namedAreaMap) { - - List groupName = Arrays.asList("0", "穀類", "いも及びでん粉類", "砂糖及び甘味類", "豆類", - "種実類", "野菜類", "果実類", "きのこ類", "藻類", "魚介類", "肉類", "卵類", "乳類", - "油脂類", "菓子類", "し好飲料類", "調味料及び香辛料類", "調理加工食品類"); - - - - Row groupRow = calcSheet.createRow(rowIndex); - groupRow.createCell(1).setCellValue("食品群"); - groupRow.createCell(3).setCellValue("摂取量(g)"); - rowIndex++; - - for(int i = 1; i <= 18; i++,rowIndex++) { - Row thisRow = calcSheet.createRow(rowIndex); - thisRow.createCell(1).setCellValue(i); - thisRow.createCell(2).setCellValue(groupName.get(i)); - Cell cCell = thisRow.createCell(3); - cCell.setCellStyle(csPool.getCellStyle("")); - //cCell.setCellFormula("SUMIF(AREA_GROUP, " + i + ", AREA_INTAKE)"); - cCell.setCellFormula("SUMIF(" + _namedAreaMap.get("AREA_GROUP") + ", " + i + ", " + _namedAreaMap.get("AREA_INTAKE") + ")"); - - if(i == 6) { - rowIndex++; - thisRow = calcSheet.createRow(rowIndex); - thisRow.createCell(2).setCellValue("うち 緑黄色野菜"); - Cell bcvCell = thisRow.createCell(3); - bcvCell.setCellStyle(csPool.getCellStyle("0")); - //bcvCell.setCellFormula("SUMIF(AREA_BRIGHT_COLORED_VEGETABLE, 1, AREA_INTAKE)"); - bcvCell.setCellFormula("SUMIF(" + _namedAreaMap.get("AREA_BRIGHT_COLORED_VEGETABLE") + ", 1, " + _namedAreaMap.get("AREA_INTAKE") + ")"); - } - - - } - - return rowIndex; - } //「付加行」生成 private static int generateAddition(String fileName, Sheet calcSheet, CellStylePool csPool, int rowIndex, Map _namedAreaMap) { - System.out.println("ADDITION : " + fileName); - AdditionConfig ac = AdditionUtil.additionFileReader(new File(fileName)); for(AcRow acRow : ac.getRows()) { //行ごとのループ Row thisRow = calcSheet.createRow(rowIndex); @@ -280,8 +229,9 @@ public class Nucalgen { _namedAreaMap.put(acCell.getAlias(), new CellReference(rowIndex, colIndex, true, true).formatAsString()); } - if(acCell.getCellType() == AcCellType.FORMULA) { - String formula = "<" + acCell.getValue() + ">"; + //formula 計算式 + if(acCell.getFormula() != null){ + String formula = "<" + acCell.getFormula() + ">"; for(Entry keyValue : _namedAreaMap.entrySet()) { String k = keyValue.getKey(); String v = keyValue.getValue(); @@ -291,8 +241,14 @@ public class Nucalgen { formula = formula.replaceAll(">$", ""); } thisCell.setCellFormula(formula); - } else { + + //value そのままの値 + } else if(acCell.getValue() != null) { thisCell.setCellValue(acCell.getValue()); + + //formula でも value でもない + } else { + // } diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCell.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCell.java index b2d881d..20a07df 100644 --- a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCell.java +++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCell.java @@ -2,11 +2,11 @@ package jp.satomichan.nucalgen.addition; public class AcCell { private String value; - private AcCellType type; + private String formula; private String alias; public AcCell(){ - //System.out.println("Cell#Cell()"); + // } public String getValue() { @@ -16,28 +16,7 @@ public class AcCell { public void setValue(String value) { this.value = value; } - - - public AcCellType getCellType() { - return type; - } - - public String getType() { - return type.getId(); - } - - public void setType(String type) { - AcCellType[] types = AcCellType.values(); - for(AcCellType aType : types) { - if(aType.getId().equals(type)){ - this.setType(aType); - } - } - } - - private void setType(AcCellType type) { - this.type = type; - } + public String getAlias() { return alias; @@ -46,4 +25,12 @@ public class AcCell { public void setAlias(String alias) { this.alias = alias; } + + public String getFormula() { + return formula; + } + + public void setFormula(String formula) { + this.formula = formula; + } } diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCellType.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCellType.java deleted file mode 100644 index a3074e2..0000000 --- a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AcCellType.java +++ /dev/null @@ -1,17 +0,0 @@ -package jp.satomichan.nucalgen.addition; - -public enum AcCellType { - FORMULA("formula"), - STRING("string"); - - private String id; - - - private AcCellType(String id) { - this.id = id; - } - - public String getId() { - return id; - } -} diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AdditionUtil.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AdditionUtil.java index 8b03346..ba1f489 100644 --- a/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AdditionUtil.java +++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/addition/AdditionUtil.java @@ -13,11 +13,6 @@ import org.xml.sax.SAXException; public class AdditionUtil { - public static void main(String[] args) { - AdditionConfig add = additionFileReader(new File("C:\\Users\\h520s\\Desktop\\pfc-balance.xml")); - } - - public static AdditionConfig additionFileReader(File reportXmlFile){ SAXParserFactory factory = SAXParserFactory.newInstance(); javax.xml.parsers.SAXParser parser = null; @@ -37,7 +32,7 @@ public class AdditionUtil { digester.addObjectCreate("addition/row/cell", AcCell.class); digester.addSetNext("addition/row/cell", "addCell"); - digester.addBeanPropertySetter("addition/row/cell/type"); + digester.addBeanPropertySetter("addition/row/cell/formula"); digester.addBeanPropertySetter("addition/row/cell/value"); digester.addBeanPropertySetter("addition/row/cell/alias"); @@ -54,6 +49,6 @@ public class AdditionUtil { } return addition; - } + }