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 MextStdFoodCompTable {
15 private String brightColoredVegetablesXmlFileName = "";
16 private List<String> brightColoredVegetableList = new ArrayList<String>();
18 MextStdFoodCompTable(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 foodComposithonSheet = outputWorkbook.cloneSheet(0);
38 outputWorkbook.setSheetName(18, "成分表");
39 outputWorkbook.setSheetOrder("成分表", 0);
42 Row idRow = foodComposithonSheet.getRow(10);
43 for(int i = 4; i <= 61; i++) {
44 Cell idCell = idRow.getCell(i);
45 idCell.setCellValue(idCell.toString().replaceAll(" ", ""));
47 idRow.createCell(62).setCellValue("GROUP");
48 idRow.createCell(63).setCellValue("BRIGHT_COLORED_VEGETABLE");
50 int compSheetRowIndex = 11;
53 for(int group = 1; group <= 18; group++) {
54 Sheet thisSheet = outputWorkbook.getSheetAt(group);
57 for (Row thisRow : thisSheet) {
59 if(rowCount < 12) {continue;}
61 Row compRow = foodComposithonSheet.createRow(compSheetRowIndex);
63 for (int cellCount = 1; cellCount <= 61; cellCount++) {
64 Cell thisCell = thisRow.getCell(cellCount);
66 String cellString = thisCell.toString();
68 cellString = cellString.replaceAll("\\(", "");
69 cellString = cellString.replaceAll("\\)", "");
70 cellString = cellString.replaceAll("-", "0");
71 cellString = cellString.replaceAll("Tr", "0");
74 //Cell compCell = foodComposithonSheet.getRow(compSheetRowIndex).getCell(cellCount);
75 Cell compCell = compRow.createCell(cellCount);
76 compCell.setCellValue(cellString);
77 compCell.setCellStyle(thisCell.getCellStyle());
78 compCell.setCellType(thisCell.getCellTypeEnum());
80 if(cellString.matches("^[\\d\\.]+$")) {
81 compCell.setCellValue(Double.parseDouble(cellString));
82 CellStyle aCellStyle = compCell.getCellStyle();
83 aCellStyle.setDataFormat((short) 0);
84 compCell.setCellStyle(aCellStyle);
93 compRow.createCell(62).setCellValue(group);
96 boolean isBrightColored = false;
97 if(group == 6 && brightColoredVegetablesXmlFileName.length() > 0) {
98 String foodName = thisRow.getCell(3).getStringCellValue();
99 for(String aBright : this.brightColoredVegetableList) {
100 if(foodName.matches(".*" + aBright + ".*")) {
101 isBrightColored = true;
106 if(isBrightColored) {
107 compRow.createCell(63).setCellValue(1);
119 for(int i = 18; i > 0; i--) {
120 outputWorkbook.removeSheetAt(i);