StoragePosXlsParser.java
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.myproject.poi;
import com.csvreader.CsvReader;
import com.myproject.bean.excel.StoragePosExcel;
import com.myproject.exception.ExcelParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import java.io.IOException;
import java.util.List;
/**
* Created by kangmor on 2015/11/17.
*/
public class StoragePosXlsParser extends BaseXlsParser {
private final static String[] titles = new String[]{"位置","优先级", "高度", /*"层数", "夹板厚度",
"取料前点", "取料点", "投料前点", "投料点", "起点", "终点", "偏差1", "偏差2", "偏差3", "偏差4",
"左右边", "X轴行走", "Z(左右)", "皮带放料点",*/ "宽度"
};
private final static int EXT_DATA_SIZE = 50;
@Override
protected Object readData(HSSFRow hssfRow, HSSFRow startRow) throws ExcelParseException {
StoragePosExcel storagePos = new StoragePosExcel();
storagePos.setPosName(getValue(hssfRow.getCell(0)));
String data = "";
int errorColumn = 0;
try {
//storagePos.setH(hssfRow.getCell(1).getNumericCellValue());
if (!StringUtils.isEmpty(getValue(hssfRow.getCell(1))))
storagePos.setPriority(Double.valueOf(getValue(hssfRow.getCell(1))));
if (!StringUtils.isEmpty(getValue(hssfRow.getCell(2))))
storagePos.setH(Double.valueOf(getValue(hssfRow.getCell(2))).intValue());
if (!StringUtils.isEmpty(getValue(hssfRow.getCell(3))))
storagePos.setW(Double.valueOf(getValue(hssfRow.getCell(3))).intValue());
for (int i = 4; i < 100; i++) {
errorColumn = i+1;
//位置Dxxx
String posDxx = getValue(startRow.getCell(i));
if (!StringUtils.isEmpty(posDxx)) {
String cellValue = getValue(hssfRow.getCell(i));
if (!StringUtils.isEmpty(cellValue)) {
data += posDxx + ":" + cellValue + "#";
}
}
}
} catch (Exception e) {
log.error(e);
int errorRow = hssfRow.getRowNum() + 1;
log.error("Number parse error at row: " + errorRow + " and column: "+errorColumn);
log.error(e);
throw new ExcelParseException("Excel解析错误在第" + errorRow + "行,"+errorColumn +"列");
}
return storagePos;
}
@Override
protected String[] getTitles() {
return titles;
}
}