通过miniui解析Excel数据

阅读更多
//前端js脚本


//Action类
private Map mapData; 
public Map getMapData() {
return mapData;
}

public void setMapData(Map mapData) {
this.mapData = mapData;
}

public String doImportData() throws Exception {

//读取数据存放list
List listData = new ArrayList();

try {
HttpServletRequest request = ServletActionContext.getRequest();
request.setCharacterEncoding("UTF-8");
String fileName = request.getParameter("inputFile");
//读取excel文件
FileInputStream inputStream = new FileInputStream(fileName);
//将输出流转为Workbook对象
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
//获取工作表
HSSFSheet sheet = workbook.getSheetAt(0);
//获取行
int num = sheet.getPhysicalNumberOfRows();
for(int i=0;i if(i>7){
HSSFRow row = sheet.getRow(i);
if(row!=null){

HSSFCell cell1 = row.getCell(1);
HSSFCell cell2 = row.getCell(2);
HSSFCell cell3 = row.getCell(3);
HSSFCell cell4 = row.getCell(4);
HSSFCell cell5 = row.getCell(5);
HSSFCell cell6 = row.getCell(6);

HSSFCell cell7 = row.getCell(7);
HSSFCell cell8 = row.getCell(8);
HSSFCell cell9 = row.getCell(9);
HSSFCell cell10 = row.getCell(10);
HSSFCell cell11 = row.getCell(11);
HSSFCell cell12 = row.getCell(12);

HSSFCell cell13 = row.getCell(13);
HSSFCell cell14 = row.getCell(14);
HSSFCell cell15 = row.getCell(15);
HSSFCell cell16 = row.getCell(16);
HSSFCell cell17 = row.getCell(17);
HSSFCell cell18 = row.getCell(18);

//临时存放数据
Map mapData = new HashMap();
if(cell1.getStringCellValue() == ""){
break;
}
mapData.put("xh", cell1.getStringCellValue());
mapData.put("hjjd", cell2.getStringCellValue());
mapData.put("hjjw", cell3.getStringCellValue());
mapData.put("name", cell4.getStringCellValue());
mapData.put("sex", cell5.getStringCellValue());
mapData.put("zjlx", cell6.getStringCellValue());
mapData.put("zjhm", cell7.getStringCellValue());
mapData.put("mz", cell8.getStringCellValue());
mapData.put("csrq", cell9.getStringCellValue());
mapData.put("whcd", cell10.getStringCellValue());
mapData.put("hkdz", cell11.getStringCellValue());
mapData.put("dclx", cell12.getStringCellValue());
mapData.put("mqzk", cell13.getStringCellValue());
mapData.put("mdrq", cell14.getStringCellValue());
mapData.put("dqyx", cell15.getStringCellValue());
mapData.put("cjr", cell16.getStringCellValue());
mapData.put("zjgzjsrq", cell17.getStringCellValue());
mapData.put("cshrq", cell18.getStringCellValue());

listData.add(mapData);
}
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mapData = new HashMap();
mapData.put("data", listData);
return SUCCESS;
}

//配置文件,使用Struts2将map转json格式
method="doImportData">

mapData



你可能感兴趣的:(excel,json,struts)