jsp页面
后台接收
调用处理
pom文件
不能下载,改写setting文件,添加maven2资源库
<form class="form_0" id="form1" enctype="multipart/form-data" method="post" action="importToContent.aa">
<input class=" wd_50 btn" type="button" name="back" value="返回" onclick="javascript:window.history.go(-1)" />
<input class=" wd_50 btn" type="button" name="subtn" value="提交" /><label><span class="labelTitle">上传文件地址:</span>
<input type="file" name="excelFile" id="Cname" value="" size="45"/>
</form>
后台接收
//excel文件批量导入短信
@RequestMapping("/importToContent.aa")
public ModelAndView importToContent(HttpServletRequest request,@RequestParam("excelFile") MultipartFile file) throws Exception{
scm.readExcelWriteData(file.getInputStream());
return new ModelAndView("/frames/so_Groupsms_into");
}
调用处理
public int readExcelWriteData(InputStream inp) throws Exception{
Workbook wb = WorkbookFactory.create(inp);
int numberRow;
//获取第一张表
Sheet st = wb.getSheetAt(0);
//获取行数 st.getLastRowNum();
//存储读取的短信
List smsContentList = new ArrayList();
String smsCon = null;
//遍历第一张表的所有行
for(int i=0;i<=st.getLastRowNum();i++){
//第一行一般为title不读取
if(i!=0){
Row row = st.getRow(i); //获取第一行数据
//遍历第一行所有的列(单元格)
for(int j=0;j<row.getLastCellNum();j++){
Cell cell = row.getCell(j); //获取第一个单元格
//获取单元格类型
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING: //字符串
System.out.println(cell.getRichStringCellValue().getString());
smsCon = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC: //数字
if (DateUtil.isCellDateFormatted(cell)) { //判断是否包含日期
System.out.println(cell.getDateCellValue());
} else {
System.out.println(cell.getNumericCellValue());
smsCon = String.valueOf(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN: //布尔
//System.out.println(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA: //公式
//System.out.println(cell.getCellFormula());
break;
default:
System.out.println();
}
}
}
if(smsCon!=null&&!smsCon.equals("")){
smsContentList.add(smsCon);
}
}
System.out.println("----------------"+smsContentList.size()+"--------------------");
return 0;
}
pom文件
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.7</version>
</dependency>
不能下载,改写setting文件,添加maven2资源库
<mirror>
<id>mav.mt</id>
<url>http://repo1.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
<!-- Spain, Sevilla -->
</mirror>