From 7deca54cbc7880747faac12d9042666d78f5355f Mon Sep 17 00:00:00 2001 From: satomichan Date: Thu, 11 Feb 2021 05:23:59 +0900 Subject: [PATCH] =?utf8?q?=E6=A0=84=E9=A4=8A=E4=BE=A1=E8=A8=88=E7=AE=97?= =?utf8?q?=E3=81=AE=E9=A0=85=E7=9B=AE=E3=81=AB=E5=90=AB=E3=81=BE=E3=82=8C?= =?utf8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=80=81=E4=B8=8D=E8=A6=81?= =?utf8?q?=E3=81=AA=E8=A1=A8=E3=81=AE=E3=82=B7=E3=83=BC=E3=83=88=EF=BC=88e?= =?utf8?q?x.=E8=84=82=E8=82=AA=E9=85=B8=E6=88=90=E5=88=86=E8=A1=A8?= =?utf8?q?=EF=BC=89=E3=82=92=E5=87=BA=E5=8A=9B=E3=81=97=E3=81=AA=E3=81=84?= =?utf8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/jp/satomichan/nucalgen/Nucalgen.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/jp/satomichan/nucalgen/Nucalgen.java b/src/main/java/jp/satomichan/nucalgen/Nucalgen.java index 690d47d..f37b8b0 100644 --- a/src/main/java/jp/satomichan/nucalgen/Nucalgen.java +++ b/src/main/java/jp/satomichan/nucalgen/Nucalgen.java @@ -2,6 +2,7 @@ package jp.satomichan.nucalgen; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -96,6 +97,7 @@ public class Nucalgen { } //「栄養計算」行 + List usedTableList = new ArrayList(); int rowIndex = 3; for(int i = rowIndex; i < lines + 3; i++,rowIndex++) { Row thisRow = calcSheet.createRow(rowIndex); @@ -113,6 +115,8 @@ public class Nucalgen { thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + "," + aColumn.getTable() + "!$B$12:$BL$2500,MATCH(\"" + aColumn.getName() + "\"," + aColumn.getTable() + "!$B$11:$BL$11,0),FALSE) " + div100 + ",\"\")"); colIndex++; + + usedTableList.add(aColumn.getTable()); } } @@ -171,6 +175,21 @@ public class Nucalgen { rowIndex = generateGroupSum(calcSheet, csPool, rowIndex, namedAreaMap); } + + //未使用表シート削除 + 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); + } + } + //ブック出力 FileOutputStream outputXlsxFile = new FileOutputStream(outputXlsxFileName); outputWorkbook.setActiveSheet(0); -- 2.43.0