From: satomichan <...@...>
Date: Sat, 10 Jul 2021 05:45:27 +0000 (+0900)
Subject: ひとまず実装できた。
X-Git-Tag: JAR_2021-07-10_0729_BUILD~1
X-Git-Url: https://satomichan.jp/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FMULTI_SHEETS;p=nucalgen
ひとまず実装できた。
---
diff --git a/nucalgen/pom.xml b/nucalgen/pom.xml
index 7bf56ff..fe18332 100644
--- a/nucalgen/pom.xml
+++ b/nucalgen/pom.xml
@@ -37,6 +37,14 @@
commons-digester
2.1
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.12.0
+
+
diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/NamedAreaStore.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/NamedAreaStore.java
index 095499e..2f2f679 100644
--- a/nucalgen/src/main/java/jp/satomichan/nucalgen/NamedAreaStore.java
+++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/NamedAreaStore.java
@@ -4,7 +4,9 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.regex.Matcher;
+import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.util.CellReference;
public class NamedAreaStore {
@@ -33,7 +35,7 @@ public class NamedAreaStore {
String save(String areaname, int row1, int col1, int row2, int col2) {
String area = getAreaString(row1, col1, row2, col2);
-
+ areaname = Matcher.quoteReplacement(areaname);
this.namedAreaMap.put(areaname, area);
return area;
@@ -45,7 +47,13 @@ public class NamedAreaStore {
}
+ String save(String areaname, Cell cell) {
+ return this.save(areaname, cell.getRowIndex(), cell.getColumnIndex());
+ }
+
+
String load(String areaName) {
+ areaName = Matcher.quoteReplacement(areaName);
return this.namedAreaMap.get(areaName);
}
diff --git a/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java b/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java
index 941f552..2068900 100644
--- a/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java
+++ b/nucalgen/src/main/java/jp/satomichan/nucalgen/Nucalgen.java
@@ -13,6 +13,7 @@ import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
+import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
@@ -39,6 +40,7 @@ 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("sheets").hasArgs().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());
@@ -69,162 +71,329 @@ public class Nucalgen {
//ãæ é¤ä¾¡è¨ç®ãã·ã¼ãçæ
- Sheet calcSheet = outputWorkbook.createSheet("æ é¤ä¾¡è¨ç®");
- outputWorkbook.setSheetOrder("æ é¤ä¾¡è¨ç®", 0);
- if(cmd.hasOption("set-protect")) {
- calcSheet.protectSheet("");
+ CellStylePool csPool = new CellStylePool(outputWorkbook);
+ List usedTableList = new ArrayList();
+ List sheetNameList = new ArrayList();
+
+
+ String[] sheets = cmd.getOptionValues("sheets");
+ if(sheets != null && sheets.length >= 2) {
+ //表ãè¤æ°
+ for(int si = 0; si < sheets.length - 1; si++) {
+ final String sheetName = sheets[si];
+ generateCalculationSheet(outputWorkbook, sheetName, namedArea, cmd.hasOption("set-protect"), cmd.getOptionValues("addition"), lines, nch, csPool, usedTableList);
+ outputWorkbook.setSheetOrder(sheetName, si);
+ sheetNameList.add(sheetName);
+ }
+ final String sumSheetName = sheets[sheets.length - 1];
+ generateSumSheet(outputWorkbook, sumSheetName, sheetNameList, namedArea, cmd.hasOption("set-protect"), cmd.getOptionValues("addition"), lines, nch, csPool, usedTableList);
+ outputWorkbook.setSheetOrder(sumSheetName, sheets.length - 1);
+
+ }else {
+ //表ãã²ã¨ã¤
+ final String sheetName = (sheets != null) ? sheets[0] : "æ é¤ä¾¡è¨ç®";
+ generateCalculationSheet(outputWorkbook, sheetName, namedArea, cmd.hasOption("set-protect"), cmd.getOptionValues("addition"), lines, nch, csPool, usedTableList);
+ outputWorkbook.setSheetOrder(sheetName, 0);
+ sheetNameList.add(sheetName);
+ }
+
+
+ //æªä½¿ç¨è¡¨ã·ã¼ãåé¤
+ for(int si = outputWorkbook.getNumberOfSheets() - 1 ; si >= 1 ; si--) {
+ String sheetName = outputWorkbook.getSheetName(si);
+ boolean used = false;
+ for(String usedTable : usedTableList) {
+ if(usedTable.equals(sheetName)) {
+ used = true;
+ }
+ }
+ if(!used) {
+ outputWorkbook.removeSheetAt(si);
+ }
}
- calcSheet.setColumnWidth(COL_INDEX_START -2, 10240); //Cãé£ååãå
- calcSheet.addMergedRegion(new CellRangeAddress(ROW_INDEX_START -2, ROW_INDEX_START -1,
- COL_INDEX_START -3, COL_INDEX_START -3)); //B2:B3ãé£åçªå·ãã»ã«
+
+ //ããã¯åºå
+ FileOutputStream outputXlsxFile = new FileOutputStream(outputXlsxFileName);
+ outputWorkbook.setActiveSheet(0);
+
+ outputWorkbook.setSelectedTab(0);
+ outputWorkbook.write(outputXlsxFile);
+ outputWorkbook.close();
+
+ } catch (Exception e) {
+ // TODO èªåçæããã catch ãããã¯
+ e.printStackTrace();
+ }
+ }
- CellStylePool csPool = new CellStylePool(outputWorkbook);
- //ãã¿ã¤ãã«ãè¡
- Row titleRow = calcSheet.createRow(ROW_INDEX_START -2);
- titleRow.createCell(COL_INDEX_START -3).setCellValue("é£åçªå·");
- titleRow.createCell(COL_INDEX_START -2).setCellValue("é£åå");
- titleRow.createCell(COL_INDEX_START -1).setCellValue("æåé");
- int colIndex = COL_INDEX_START;
- for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
- titleRow.createCell(colIndex).setCellValue(aColumn.getDispName());
- colIndex++;
- }
- //ãåä½ãè¡
- Row unitRow = calcSheet.createRow(ROW_INDEX_START -1);
- unitRow.createCell(COL_INDEX_START -2).setCellValue("åä½");
- unitRow.createCell(COL_INDEX_START -1).setCellValue("g");
+
+
+
+
+
+ //ãæ é¤ä¾¡è¨ç®ãã·ã¼ãçæ
+ private static void generateCalculationSheet(Workbook book, String sheetName, NamedAreaStore namedArea, boolean setProtect,
+ String[] additionOptionValues, final int lines,
+ NutritionColumnHolder nch, CellStylePool csPool, List usedTableList) {
+
+
+ Sheet calcSheet = book.createSheet(sheetName);
+
+ if(setProtect) {
+ calcSheet.protectSheet("");
+ }
+ calcSheet.setColumnWidth(COL_INDEX_START -2, 10240); //Cãé£ååãå
+ calcSheet.addMergedRegion(new CellRangeAddress(ROW_INDEX_START -2, ROW_INDEX_START -1,
+ COL_INDEX_START -3, COL_INDEX_START -3)); //B2:B3ãé£åçªå·ãã»ã«
+
+
+ //ãã¿ã¤ãã«ãè¡
+ Row titleRow = calcSheet.createRow(ROW_INDEX_START -2);
+ titleRow.createCell(COL_INDEX_START -3).setCellValue("é£åçªå·");
+ titleRow.createCell(COL_INDEX_START -2).setCellValue("é£åå");
+ titleRow.createCell(COL_INDEX_START -1).setCellValue("æåé");
+ int colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ titleRow.createCell(colIndex).setCellValue(aColumn.getDispName());
+ colIndex++;
+ }
+
+ //ãåä½ãè¡
+ Row unitRow = calcSheet.createRow(ROW_INDEX_START -1);
+ unitRow.createCell(COL_INDEX_START -2).setCellValue("åä½");
+ unitRow.createCell(COL_INDEX_START -1).setCellValue("g");
+ colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ unitRow.createCell(colIndex).setCellValue(aColumn.getUnit());
+ colIndex++;
+ }
+
+ //ãæ é¤è¨ç®ãè¡
+ int rowIndex = ROW_INDEX_START;
+ for(int i = rowIndex; i < lines + ROW_INDEX_START; i++,rowIndex++) {
+ Row thisRow = calcSheet.createRow(rowIndex);
+
+ //ãé£ååã
+ thisRow.createCell(COL_INDEX_START -3).setCellStyle(csPool.getCellStyle("00000", false));
+ thisRow.createCell(COL_INDEX_START -2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) +
+ ",æå表!$B$13:$BL$2500,3,FALSE),\"\")");
+ thisRow.createCell(COL_INDEX_START -1).setCellStyle(csPool.getCellStyle("", false));
+
colIndex = COL_INDEX_START;
for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
- unitRow.createCell(colIndex).setCellValue(aColumn.getUnit());
+ Cell thisCell = thisRow.createCell(colIndex);
+ thisCell.setCellStyle(csPool.getCellStyle(aColumn.getFormat()));
+
+ if(aColumn.getFormula().length() >= 1) {
+ //ãè¨ç®å¼ãå
+ String formula = aColumn.getFormula();
+ for(String aAlias : nch.getNutritionAliasList()) {
+ formula = replaceFormula(formula, aAlias, rowIndex, COL_INDEX_START + nch.indexOf(aAlias));
+ }
+ thisCell.setCellFormula(formula);
+
+
+ } else {
+ //éå¸¸ã®æ é¤ç´ ã®å
+ String div100 = aColumn.isUseRawValue() ? "" : "/ 100 * $D" + (rowIndex + 1);
+ 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());
+ usedTableList.add(sheetName);
}
- //ãæ é¤è¨ç®ãè¡
- List usedTableList = new ArrayList();
- int rowIndex = ROW_INDEX_START;
- for(int i = rowIndex; i < lines + ROW_INDEX_START; 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$13:$BL$2500,3,FALSE),\"\")");
- thisRow.createCell(3).setCellStyle(csPool.getCellStyle("", false));
-
- colIndex = COL_INDEX_START;
- for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
- Cell thisCell = thisRow.createCell(colIndex);
- thisCell.setCellStyle(csPool.getCellStyle(aColumn.getFormat()));
-
- if(aColumn.getFormula().length() >= 1) {
- //ãè¨ç®å¼ãå
- String formula = aColumn.getFormula();
- for(String aAlias : nch.getNutritionAliasList()) {
- formula = replaceFormula(formula, aAlias, rowIndex, COL_INDEX_START + nch.indexOf(aAlias));
- }
- thisCell.setCellFormula(formula);
+ }
- } else {
- //éå¸¸ã®æ é¤ç´ ã®å
- String div100 = aColumn.isUseRawValue() ? "" : "/ 100 * $D" + (rowIndex + 1);
- 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 + ",\"\")");
- }
+ //æåé ç¯å²ãè¨æ¶
+ namedArea.save("AREA_INTAKE", ROW_INDEX_START, COL_INDEX_START -1, rowIndex -1, COL_INDEX_START -1);
- colIndex++;
- usedTableList.add(aColumn.getTable());
- }
+ //ãåè¨ãè¡
+ Row sumRow = calcSheet.createRow(rowIndex);
+ sumRow.createCell(COL_INDEX_START -3).setCellValue("åè¨");
+ calcSheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, COL_INDEX_START -3, COL_INDEX_START -2));
+
+ //ãæåéãåè¨
+ Cell intakeSumCell = sumRow.createCell(COL_INDEX_START -1);
+ intakeSumCell.setCellFormula("SUM(" + namedArea.load("AREA_INTAKE") + ")");
+ namedArea.save("SUM_INTAKE", intakeSumCell);
+
+ colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ Cell thisCell = sumRow.createCell(colIndex);
+ //ç¯å²ãè¨æ¶
+ String areaName = aColumn.getAlias().length() >= 1 ? ("AREA_" + aColumn.getAlias()) : ("AREAID_" + aColumn.getName());
+ namedArea.save(areaName, ROW_INDEX_START, colIndex, rowIndex -1, colIndex);
+
+ if(aColumn.isUseSum()) {
+ String sumName = aColumn.getAlias().length() >= 1 ? ("SUM_" + aColumn.getAlias()) : ("SUMID_" + aColumn.getName());
+ namedArea.save(sumName, thisCell);
}
+ thisCell.setCellStyle(csPool.getCellStyle(aColumn.getFormat()));
+ if(aColumn.isUseSum()) {
+ thisCell.setCellFormula("SUM(" +
+ NamedAreaStore.getAreaString(ROW_INDEX_START, colIndex, rowIndex -1, colIndex) +
+ ")");
+ }
+ colIndex++;
+ }
- //æåé ç¯å²ãè¨æ¶
- namedArea.save("AREA_INTAKE", ROW_INDEX_START, COL_INDEX_START -1, rowIndex -1, COL_INDEX_START -1);
+
+ //ãä»å è¡ãåºå
+ if(additionOptionValues != null) {
+ for(String aAdditionFileName : additionOptionValues) {
+ rowIndex += 2;
+ rowIndex = generateAddition(aAdditionFileName, calcSheet, null, csPool, rowIndex, namedArea);
+ }
+ }
+
+ calcSheet.setForceFormulaRecalculation(true);
+ }
- //ãåè¨ãè¡
- Row sumRow = calcSheet.createRow(rowIndex);
- sumRow.createCell(1).setCellValue("åè¨");
- calcSheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 1, 3));
- colIndex = COL_INDEX_START;
- for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
- Cell thisCell = sumRow.createCell(colIndex);
- //ç¯å²ãè¨æ¶ï¼alias ããã°è¨å®ï¼
- if(aColumn.getAlias().length() > 0) {
- namedArea.save("AREA_" + aColumn.getAlias(), ROW_INDEX_START, colIndex, rowIndex -1, colIndex);
+
+
+
+ //éè¨ç¨ã·ã¼ãçæ
+ private static void generateSumSheet(Workbook book, String sheetName, List sheetNameList, NamedAreaStore namedArea, boolean setProtect,
+ String[] additionOptionValues, final int lines,
+ NutritionColumnHolder nch, CellStylePool csPool, List usedTableList) {
- if(aColumn.isUseSum()) {
- namedArea.save("SUM_" + aColumn.getAlias(), rowIndex, colIndex);
- }
- }
+ usedTableList.add(sheetName);
+ Sheet sheet = book.createSheet(sheetName);
+
+ if(setProtect) {
+ sheet.protectSheet("");
+ }
+
+ //ã表ã
+ sheet.setColumnWidth(COL_INDEX_START -2, 10240); //C
+ sheet.addMergedRegion(new CellRangeAddress(ROW_INDEX_START -2, ROW_INDEX_START -1,
+ COL_INDEX_START -3, COL_INDEX_START -2)); //B2:C3ã表ãã»ã«
+
+
+ //ãã¿ã¤ãã«ãè¡
+ Row titleRow = sheet.createRow(ROW_INDEX_START -2);
+ titleRow.createCell(COL_INDEX_START -3).setCellValue("表");
+ titleRow.createCell(COL_INDEX_START -1).setCellValue("æåé");
+ int colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ titleRow.createCell(colIndex).setCellValue(aColumn.getDispName());
+ colIndex++;
+ }
+
+ //ãåä½ãè¡
+ Row unitRow = sheet.createRow(ROW_INDEX_START -1);
+ unitRow.createCell(COL_INDEX_START -2).setCellValue("åä½");
+ unitRow.createCell(COL_INDEX_START -1).setCellValue("g");
+ colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ unitRow.createCell(colIndex).setCellValue(aColumn.getUnit());
+ colIndex++;
+ }
+
+ //表ãã¨ã®å°è¨
+ int rowIndex = ROW_INDEX_START;
+ for(String aSheetName : sheetNameList) {
+ Row thisRow = sheet.createRow(rowIndex);
+
+ sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex,
+ COL_INDEX_START -3, COL_INDEX_START -2)); //B:Cã表ãã»ã«
+ //ã表ãå
+ thisRow.createCell(COL_INDEX_START -3).setCellValue(aSheetName);
+
+ //ãæåéãå
+ thisRow.createCell(COL_INDEX_START -1).setCellFormula(aSheetName + "!" + namedArea.load("SUM_INTAKE"));
+
+
+ //ã表ãã¨ã®å°è¨ãå
+ colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ Cell thisCell = thisRow.createCell(colIndex);
thisCell.setCellStyle(csPool.getCellStyle(aColumn.getFormat()));
if(aColumn.isUseSum()) {
- thisCell.setCellFormula("SUM(" +
- NamedAreaStore.getAreaString(ROW_INDEX_START, colIndex, rowIndex -1, colIndex) +
- ")");
+ String sumName = aColumn.getAlias().length() >= 1 ? ("SUM_" + aColumn.getAlias()) : ("SUMID_" + aColumn.getName());
+ String formula = aSheetName + "!" + namedArea.load(sumName);
+ thisCell.setCellFormula(formula);
}
+
colIndex++;
- }
-
- //ãä»å è¡ãåºå
- String[] additionOptionValues = cmd.getOptionValues("addition");
- if(additionOptionValues != null) {
- for(String aAdditionFileName : additionOptionValues) {
- rowIndex += 2;
- rowIndex = generateAddition(aAdditionFileName, calcSheet, csPool, rowIndex, namedArea);
- }
}
+ rowIndex++;
+ }
- //æªä½¿ç¨è¡¨ã·ã¼ãåé¤
- for(int si = outputWorkbook.getNumberOfSheets() - 1 ; si >= 1 ; si--) {
- String sheetName = outputWorkbook.getSheetName(si);
- boolean used = false;
- for(String usedTable : usedTableList) {
- if(usedTable.equals(sheetName)) {
- used = true;
- }
- }
- if(!used) {
- outputWorkbook.removeSheetAt(si);
- }
+
+ //æåé ç¯å²ãè¨æ¶
+ namedArea.save("AREA_INTAKE", ROW_INDEX_START, COL_INDEX_START -1, rowIndex -1, COL_INDEX_START -1);
+
+ //ãåè¨ãè¡
+ Row sumRow = sheet.createRow(rowIndex);
+ sumRow.createCell(COL_INDEX_START -3).setCellValue("åè¨");
+ sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, COL_INDEX_START -3, COL_INDEX_START -2));
+
+ Cell intakeSumCell = sumRow.createCell(COL_INDEX_START -1);
+ intakeSumCell.setCellFormula("SUM(" + namedArea.load("AREA_INTAKE") + ")");
+
+
+ colIndex = COL_INDEX_START;
+ for(NutritionColumn aColumn : nch.getNutritionColumnList()) {
+ Cell thisCell = sumRow.createCell(colIndex);
+
+ //ç¯å²ãè¨æ¶
+ String areaName = aColumn.getAlias().length() >= 1 ? ("AREA_" + aColumn.getAlias()) : ("AREAID_" + aColumn.getName());
+ namedArea.save(areaName, ROW_INDEX_START, colIndex, rowIndex -1, colIndex);
+
+ if(aColumn.isUseSum()) {
+ String sumName = aColumn.getAlias().length() >= 1 ? ("SUM_" + aColumn.getAlias()) : ("SUMID_" + aColumn.getName());
+ namedArea.save(sumName, thisCell);
}
- //ããã¯åºå
- FileOutputStream outputXlsxFile = new FileOutputStream(outputXlsxFileName);
- outputWorkbook.setActiveSheet(0);
- calcSheet.setForceFormulaRecalculation(true);
- outputWorkbook.setSelectedTab(0);
- outputWorkbook.write(outputXlsxFile);
- outputWorkbook.close();
- } catch (Exception e) {
- // TODO èªåçæããã catch ãããã¯
- e.printStackTrace();
+ thisCell.setCellStyle(csPool.getCellStyle(aColumn.getFormat()));
+ if(aColumn.isUseSum()) {
+ thisCell.setCellFormula("SUM(" +
+ NamedAreaStore.getAreaString(ROW_INDEX_START, colIndex, rowIndex -1, colIndex) +
+ ")");
+ }
+ colIndex++;
}
- }
+
+ //ãä»å è¡ãåºå
+ if(additionOptionValues != null) {
+ for(String aAdditionFileName : additionOptionValues) {
+ rowIndex += 2;
+ rowIndex = generateAddition(aAdditionFileName, sheet, sheetNameList, csPool, rowIndex, namedArea);
+ }
+ }
+
+ sheet.setForceFormulaRecalculation(true);
-
-
-
+ }
//ãä»å è¡ãçæ
- private static int generateAddition(String fileName, Sheet calcSheet, CellStylePool csPool, int rowIndex,
+ private static int generateAddition(String fileName, Sheet calcSheet, List sheetNameList, CellStylePool csPool, int rowIndex,
NamedAreaStore namedArea) {
AdditionConfig ac = AdditionUtil.additionFileReader(new File(fileName));
+ int cellCounter = 0;
for(AcRow acRow : ac.getRows()) { //è¡ãã¨ã®ã«ã¼ã
Row thisRow = calcSheet.createRow(rowIndex);
int colIndex = 0;
@@ -232,6 +401,12 @@ public class Nucalgen {
for(AcCell acCell : acRow.getCells()) { //ã»ã«ãã¨ã®ã«ã¼ã
Cell thisCell = thisRow.createCell(colIndex);
+ cellCounter++;
+ if(sheetNameList == null) {
+ String areaName = "ADDITION_" + fileName + "_" + cellCounter;
+ namedArea.save(areaName, rowIndex, colIndex);
+ }
+
//alias ãä»å è¡ãå
ã®å¥åå®ç¾©ï¼å¶ç´ï¼å³æ¹ã»ä¸æ¹ã®ã»ã«ããããåç
§ã§ããªãï¼
if(acCell.getAlias() != null) {
namedArea.save(acCell.getAlias(), rowIndex, colIndex);
@@ -240,11 +415,24 @@ public class Nucalgen {
//formula è¨ç®å¼
if(acCell.getFormula() != null){
String formula = acCell.getFormula();
- for(Entry keyValue : namedArea.entrySet()) {
- String k = keyValue.getKey();
- String v = keyValue.getValue();
+
+ if(sheetNameList != null && formula.indexOf("AREA_") != -1) {
+ //éè¨ã·ã¼ã && ååä»ãç¯å² AREA_ ã対象ã«å«ã¾ãã
+ List sumTarget = new ArrayList();
+ for(String aSheetName : sheetNameList) {
+ String areaName = "ADDITION_" + fileName + "_" + cellCounter;
+ sumTarget.add(aSheetName + "!" + namedArea.load(areaName));
+ }
+ formula = "SUM(" + StringUtils.join(sumTarget, ",") + ")";
- formula = replaceFormula(formula, k, v);
+ }else {
+ //ãã以å¤
+ for(Entry keyValue : namedArea.entrySet()) {
+ String k = keyValue.getKey();
+ String v = keyValue.getValue();
+
+ formula = replaceFormula(formula, k, v);
+ }
}
thisCell.setCellFormula(formula);