level 1
greedy😘
楼主
1.客户端利用Apache Poi XSSFWorkbook对象生成Excel并插入数据,共一列48行。
2.后台是利用Apache poi sax事件进行解析的,主要是为了解析Excel中的大数据。
3.后台解析1生成的Excel时,无法获取Excel中Sheet的行列比(例如1:8),但是如何将1中的Excel在window环境中重新打开再进行解析就可以了。
@Override
public void startElement(String uri, String localName, String name,Attributes attributes) throws SAXException {
// c => 单元格
if ("c".equals(name)||"t".equals(name)||"v".equals(name)) {
// 如果下一个元素是 SST 的索引,则将nextIsString标记为true
String cellType = attributes.getValue("t");//获取单元格数据t="s"
if (cellType != null && "s".equals(cellType)) {//s表示该单元格为字符串
nextIsString = true;
}else {
nextIsString = false;
}
String r = attributes.getValue("r");//获取单元格坐标,如:A1
int firstDigit = -1;
for (int c=0; c<r.length(); ++c) {
if (Character.isDigit(r.charAt(c))) {//获取单元格坐标的数字
firstDigit = c;//获取单元格坐标中数字的角标
break;
}
}
thisColumnIndex = nameToColumn(r.substring(0, firstDigit));//获取单元格坐标中的字母
}else if (name.equals("row")) {
if (onlyFirstRow) {
totalCol = getColumns(attributes.getValue("spans"));//根据第一行获取总列数
onlyFirstRow = false;
}
}
attributes.getValue("spans")值为空
2017年06月06日 11点06分
1
2.后台是利用Apache poi sax事件进行解析的,主要是为了解析Excel中的大数据。
3.后台解析1生成的Excel时,无法获取Excel中Sheet的行列比(例如1:8),但是如何将1中的Excel在window环境中重新打开再进行解析就可以了。
@Override
public void startElement(String uri, String localName, String name,Attributes attributes) throws SAXException {
// c => 单元格
if ("c".equals(name)||"t".equals(name)||"v".equals(name)) {
// 如果下一个元素是 SST 的索引,则将nextIsString标记为true
String cellType = attributes.getValue("t");//获取单元格数据t="s"
if (cellType != null && "s".equals(cellType)) {//s表示该单元格为字符串
nextIsString = true;
}else {
nextIsString = false;
}
String r = attributes.getValue("r");//获取单元格坐标,如:A1
int firstDigit = -1;
for (int c=0; c<r.length(); ++c) {
if (Character.isDigit(r.charAt(c))) {//获取单元格坐标的数字
firstDigit = c;//获取单元格坐标中数字的角标
break;
}
}
thisColumnIndex = nameToColumn(r.substring(0, firstDigit));//获取单元格坐标中的字母
}else if (name.equals("row")) {
if (onlyFirstRow) {
totalCol = getColumns(attributes.getValue("spans"));//根据第一行获取总列数
onlyFirstRow = false;
}
}
attributes.getValue("spans")值为空