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.getSheetAt(0);
38 outputWorkbook.setSheetName(0, "成分表");
41 Row idRow = foodComposithonSheet.getRow(11);
42 for(int i = 4; i <= 61; i++) {
43 Cell idCell = idRow.getCell(i);
44 idCell.setCellValue(idCell.toString().replaceAll(" ", ""));
46 idRow.createCell(62).setCellValue("GROUP");
47 idRow.createCell(63).setCellValue("BRIGHT_COLORED_VEGETABLE");
51 for(int compSheetRowIndex = 12; compSheetRowIndex <= 9999; compSheetRowIndex++) {
52 Row compRow = foodComposithonSheet.getRow(compSheetRowIndex);
57 int group = Integer.parseInt(compRow.getCell(1).toString()) / 1000;
59 for (int cellCount = 1; cellCount <= 61; cellCount++) {
60 Cell thisCell = compRow.getCell(cellCount);
62 String cellString = thisCell.toString();
64 cellString = cellString.replaceAll("\\(", "");
65 cellString = cellString.replaceAll("\\)", "");
66 cellString = cellString.replaceAll("-", "0");
67 cellString = cellString.replaceAll("Tr", "0");
70 //Cell compCell = foodComposithonSheet.getRow(compSheetRowIndex).getCell(cellCount);
71 Cell compCell = compRow.createCell(cellCount);
72 compCell.setCellValue(cellString);
73 compCell.setCellStyle(thisCell.getCellStyle());
74 compCell.setCellType(thisCell.getCellTypeEnum());
76 if(cellString.matches("^[\\d\\.]+$")) {
77 compCell.setCellValue(Double.parseDouble(cellString));
78 CellStyle aCellStyle = compCell.getCellStyle();
79 aCellStyle.setDataFormat((short) 0);
80 compCell.setCellStyle(aCellStyle);
89 compRow.createCell(62).setCellValue(group);
92 boolean isBrightColored = false;
93 if(group == 6 && brightColoredVegetablesXmlFileName.length() > 0) {
94 String foodName = compRow.getCell(3).getStringCellValue();
95 for(String aBright : this.brightColoredVegetableList) {
96 if(foodName.matches(".*" + aBright + ".*")) {
97 isBrightColored = true;
102 if(isBrightColored) {
103 compRow.createCell(63).setCellValue(1);
108 } //for compSheetRowIndex
112 for(int i = outputWorkbook.getNumberOfSheets() - 1; i > 0; i--) {
113 outputWorkbook.removeSheetAt(i);