- //「本表」変換
+ //変換
void processInto(Workbook outputWorkbook) {
- Sheet mainSheet = outputWorkbook.getSheet("本表");
- int rowCount = 0;
- int lastCol = mainSheet.getRow(5).getLastCellNum();
- mainSheet.getRow(5).getCell(4).setCellValue("廃棄率");
- mainSheet.getRow(5).createCell(lastCol + 1).setCellValue("食品群");
- mainSheet.getRow(5).createCell(lastCol + 2).setCellValue("緑黄色野菜");
+ Sheet foodComposithonSheet = outputWorkbook.cloneSheet(0);
+ outputWorkbook.setSheetName(18, "成分表");
+ outputWorkbook.setSheetOrder("成分表", 0);
+ //Sheet foodComposithonSheet = outputWorkbook.createSheet("成分表");
+
+ //「成分識別子」行
+ Row idRow = foodComposithonSheet.getRow(10);
+ 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");
+ int compSheetRowIndex = 11;
- for (Row row : mainSheet) {
- rowCount++;
- if(rowCount < 8) {continue;}
+ //18 の食品群ごとの処理
+ for(int group = 1; group <= 18; group++) {
+ Sheet thisSheet = outputWorkbook.getSheetAt(group);
- for (Cell cell : row) {
- String cellString = cell.toString();
+ int rowCount = 0;
+ for (Row thisRow : thisSheet) {
+ rowCount++;
+ if(rowCount < 12) {continue;}
- cellString = cellString.replaceAll("\\(", "");
- cellString = cellString.replaceAll("\\)", "");
- cellString = cellString.replaceAll("-", "0");
- cellString = cellString.replaceAll("Tr", "0");
+ Row compRow = foodComposithonSheet.createRow(compSheetRowIndex);
+ for (int cellCount = 1; cellCount <= 61; cellCount++) {
+ Cell thisCell = thisRow.getCell(cellCount);
- if(cellString.matches("^[\\d\\.]+$")) {
- cell.setCellValue(Double.parseDouble(cellString));
- CellStyle aCellStyle = cell.getCellStyle();
- aCellStyle.setDataFormat((short) 0);
- cell.setCellStyle(aCellStyle);
- }
+ String cellString = thisCell.toString();
- }
+ cellString = cellString.replaceAll("\\(", "");
+ cellString = cellString.replaceAll("\\)", "");
+ cellString = cellString.replaceAll("-", "0");
+ cellString = cellString.replaceAll("Tr", "0");
- int gun = (int) row.getCell(0).getNumericCellValue();
- row.createCell(lastCol + 1).setCellValue(gun);
+ //セル値・書式 コピー
+ //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);
+ }
- //緑黄色野菜
- if(brightColoredVegetablesXmlFileName.length() > 0) {
- boolean isBrightColored = false;
- String foodName = row.getCell(3).getStringCellValue();
- for(String aBright : this.brightColoredVegetableList) {
- if(foodName.matches(aBright + ".*")) {
- isBrightColored = true;
- break;
+ } //CELL
+
+ //食品群(1~18)書き込み
+ compRow.createCell(62).setCellValue(group);
+
+
+ //緑黄色野菜か?
+ if(brightColoredVegetablesXmlFileName.length() > 0) {
+ boolean isBrightColored = false;
+ String foodName = thisRow.getCell(3).getStringCellValue();
+ for(String aBright : this.brightColoredVegetableList) {
+ if(foodName.matches(aBright + ".*")) {
+ isBrightColored = true;
+ break;
+ }
}
- }
- if(isBrightColored) {
- row.createCell(lastCol + 2).setCellValue(1);
+ if(isBrightColored) {
+ compRow.createCell(63).setCellValue(1);
+ }
}
- }
- }
+ compSheetRowIndex++;
+
+ } //ROW
+
+ } //GROUP
+ //元の表 削除
+ for(int i = 18; i > 0; i--) {
+ outputWorkbook.removeSheetAt(i);
+ }
}
+
+
+
}
Workbook outputWorkbook = WorkbookFactory.create(new FileInputStream(moeStdFoodCompTableFileName));
if(cmd.hasOption("use-processed-table") == false) {
- //「本表」変換
+ //成分表 変換
MoeStdFoodCompTable moe = new MoeStdFoodCompTable(cmd.getOptionValue("bright-colored-vegetables-list"));
moe.processInto(outputWorkbook);
}
- //「別表」削除
- outputWorkbook.removeSheetAt(1);
-
//「栄養価計算」シート生成
Sheet calcSheet = outputWorkbook.createSheet("栄養価計算");
Row thisRow = calcSheet.createRow(rowIndex);
thisRow.createCell(1).setCellStyle(csPool.getCellStyle("00000", false));
- thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",æ\9c¬è¡¨!$B$9:$BS$2199,3,FALSE),\"\")");
+ thisRow.createCell(2).setCellFormula("IFERROR(VLOOKUP(B" + (rowIndex + 1) + ",æ\88\90å\88\86表!$B$12:$BL$2500,3,FALSE),\"\")");
thisRow.createCell(3).setCellStyle(csPool.getCellStyle("", false));
colIndex = 4;
String div100 = aColumn.isUseRawValue() ? "" : "/ 100 * $D" + (rowIndex + 1);
- thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + ",æ\9c¬è¡¨!$B$9:$BS$2199,MATCH(\"" + aColumn.getName() + "\",æ\9c¬è¡¨!$B$6:$BS$6,0),FALSE) " + div100 + ",\"\")");
+ thisCell.setCellFormula("IFERROR(VLOOKUP($B" + (rowIndex + 1) + ",æ\88\90å\88\86表!$B$12:$BL$2500,MATCH(\"" + aColumn.getName() + "\",æ\88\90å\88\86表!$B$11:$BL$11,0),FALSE) " + div100 + ",\"\")");
colIndex++;
}