--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<addition>
+ <row>
+ <cell />
+ <cell><value>食品群別摂取量</value></cell>
+ </row>
+ <row>
+ <cell />
+ <cell><value>食品群</value></cell>
+ <cell><value></value></cell>
+ <cell><value>摂取量(g)</value></cell>
+ </row>
+
+ <row><cell /><cell><value>1</value></cell><cell><value>穀類</value></cell><cell><formula>SUMIF(AREA_GROUP, 1, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>2</value></cell><cell><value>いも及びでん粉類</value></cell><cell><formula>SUMIF(AREA_GROUP, 2, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>3</value></cell><cell><value>砂糖及び甘味類</value></cell><cell><formula>SUMIF(AREA_GROUP, 3, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>4</value></cell><cell><value>豆類</value></cell><cell><formula>SUMIF(AREA_GROUP, 4, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>5</value></cell><cell><value>種実類</value></cell><cell><formula>SUMIF(AREA_GROUP, 5, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>6</value></cell><cell><value>野菜類</value></cell><cell><formula>SUMIF(AREA_GROUP, 6, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value></value></cell><cell><value>うち 緑黄色野菜</value></cell><cell><formula>SUMIF(AREA_BRIGHT_COLORED_VEGETABLE, 1, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>7</value></cell><cell><value>果実類</value></cell><cell><formula>SUMIF(AREA_GROUP, 7, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>8</value></cell><cell><value>きのこ類</value></cell><cell><formula>SUMIF(AREA_GROUP, 8, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>9</value></cell><cell><value>藻類</value></cell><cell><formula>SUMIF(AREA_GROUP, 9, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>10</value></cell><cell><value>魚介類</value></cell><cell><formula>SUMIF(AREA_GROUP, 10, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>11</value></cell><cell><value>肉類</value></cell><cell><formula>SUMIF(AREA_GROUP, 11, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>12</value></cell><cell><value>卵類</value></cell><cell><formula>SUMIF(AREA_GROUP, 12, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>13</value></cell><cell><value>乳類</value></cell><cell><formula>SUMIF(AREA_GROUP, 13, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>14</value></cell><cell><value>油脂類</value></cell><cell><formula>SUMIF(AREA_GROUP, 14, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>15</value></cell><cell><value>菓子類</value></cell><cell><formula>SUMIF(AREA_GROUP, 15, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>16</value></cell><cell><value>し好飲料類</value></cell><cell><formula>SUMIF(AREA_GROUP, 16, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>17</value></cell><cell><value>調味料及び香辛料類</value></cell><cell><formula>SUMIF(AREA_GROUP, 17, AREA_INTAKE)</formula></cell></row>
+ <row><cell /><cell><value>18</value></cell><cell><value>調理加工食品類</value></cell><cell><formula>SUMIF(AREA_GROUP, 18, AREA_INTAKE)</formula></cell></row>
+
+</addition>
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;
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;
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());
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);
}
}
}
}
- //「食品群別摂取量」出力
- if(cmd.hasOption("with-group-sum")) {
- rowIndex += 3;
- rowIndex = generateGroupSum(calcSheet, csPool, rowIndex, namedAreaMap);
- }
-
//未使用表シート削除
for(int si = outputWorkbook.getNumberOfSheets() - 1 ; si >= 1 ; si--) {
}
- //群別摂取量
- private static int generateGroupSum(Sheet calcSheet, CellStylePool csPool, int rowIndex, Map<String,String> _namedAreaMap) {
-
- List<String> 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<String,String> _namedAreaMap) {
- System.out.println("ADDITION : " + fileName);
-
AdditionConfig ac = AdditionUtil.additionFileReader(new File(fileName));
for(AcRow acRow : ac.getRows()) { //行ごとのループ
Row thisRow = calcSheet.createRow(rowIndex);
_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<String, String> keyValue : _namedAreaMap.entrySet()) {
String k = keyValue.getKey();
String v = keyValue.getValue();
formula = formula.replaceAll(">$", "");
}
thisCell.setCellFormula(formula);
- } else {
+
+ //value そのままの値
+ } else if(acCell.getValue() != null) {
thisCell.setCellValue(acCell.getValue());
+
+ //formula でも value でもない
+ } else {
+ //
}