1 package jp.satomichan.nucalgen;
3 import java.util.ArrayList;
6 import org.apache.commons.configuration.ConfigurationException;
7 import org.apache.commons.configuration.XMLConfiguration;
8 import org.apache.poi.ss.usermodel.Cell;
9 import org.apache.poi.ss.usermodel.CellStyle;
10 import org.apache.poi.ss.usermodel.Row;
11 import org.apache.poi.ss.usermodel.Sheet;
12 import org.apache.poi.ss.usermodel.Workbook;
14 public class MoeStdFoodCompTable {
15 private String brightColoredVegetablesXmlFileName = "";
16 private List<String> brightColoredVegetableList = new ArrayList<String>();
18 MoeStdFoodCompTable(String brightColoredVegetablesXmlFileName_){
19 this.brightColoredVegetablesXmlFileName = brightColoredVegetablesXmlFileName_;
22 XMLConfiguration config = new XMLConfiguration(this.brightColoredVegetablesXmlFileName);
23 List<Object> vegetableNames = config.getList("bright-colored-vegetable.name");
24 for(Object vegeObj : vegetableNames) {
25 this.brightColoredVegetableList.add(vegeObj.toString());
28 } catch (ConfigurationException e) {
36 void processInto(Workbook outputWorkbook) {
37 Sheet mainSheet = outputWorkbook.getSheet("本表");
39 int lastCol = mainSheet.getRow(5).getLastCellNum();
40 mainSheet.getRow(5).getCell(4).setCellValue("廃棄率");
41 mainSheet.getRow(5).createCell(lastCol + 1).setCellValue("食品群");
42 mainSheet.getRow(5).createCell(lastCol + 2).setCellValue("緑黄色野菜");
45 for (Row row : mainSheet) {
47 if(rowCount < 8) {continue;}
49 for (Cell cell : row) {
50 String cellString = cell.toString();
52 cellString = cellString.replaceAll("\\(", "");
53 cellString = cellString.replaceAll("\\)", "");
54 cellString = cellString.replaceAll("-", "0");
55 cellString = cellString.replaceAll("Tr", "0");
58 if(cellString.matches("^[\\d\\.]+$")) {
59 cell.setCellValue(Double.parseDouble(cellString));
60 CellStyle aCellStyle = cell.getCellStyle();
61 aCellStyle.setDataFormat((short) 0);
62 cell.setCellStyle(aCellStyle);
67 int gun = (int) row.getCell(0).getNumericCellValue();
68 row.createCell(lastCol + 1).setCellValue(gun);
72 if(brightColoredVegetablesXmlFileName.length() > 0) {
73 boolean isBrightColored = false;
74 String foodName = row.getCell(3).getStringCellValue();
75 for(String aBright : this.brightColoredVegetableList) {
76 if(foodName.matches(aBright + ".*")) {
77 isBrightColored = true;
83 row.createCell(lastCol + 2).setCellValue(1);