package jp.satomichan.nucalgen; import java.util.ArrayList; import java.util.List; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; public class MoeStdFoodCompTable { private String brightColoredVegetablesXmlFileName = ""; private List brightColoredVegetableList = new ArrayList(); MoeStdFoodCompTable(String brightColoredVegetablesXmlFileName_){ this.brightColoredVegetablesXmlFileName = brightColoredVegetablesXmlFileName_; try { XMLConfiguration config = new XMLConfiguration(this.brightColoredVegetablesXmlFileName); List vegetableNames = config.getList("bright-colored-vegetable.name"); for(Object vegeObj : vegetableNames) { this.brightColoredVegetableList.add(vegeObj.toString()); } } catch (ConfigurationException e) { e.printStackTrace(); } } //「本表」変換 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("緑黄色野菜"); for (Row row : mainSheet) { rowCount++; if(rowCount < 8) {continue;} for (Cell cell : row) { String cellString = cell.toString(); cellString = cellString.replaceAll("\\(", ""); cellString = cellString.replaceAll("\\)", ""); cellString = cellString.replaceAll("-", "0"); cellString = cellString.replaceAll("Tr", "0"); if(cellString.matches("^[\\d\\.]+$")) { cell.setCellValue(Double.parseDouble(cellString)); CellStyle aCellStyle = cell.getCellStyle(); aCellStyle.setDataFormat((short) 0); cell.setCellStyle(aCellStyle); } } int gun = (int) row.getCell(0).getNumericCellValue(); row.createCell(lastCol + 1).setCellValue(gun); //緑黄色野菜 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; } } if(isBrightColored) { row.createCell(lastCol + 2).setCellValue(1); } } } } }