`
零碎的记忆
  • 浏览: 53023 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

将xls数据导入到数据库中

阅读更多
String path=ServletActionContext.getRequest().getParameter("importexcel");
String string="//";
path.replace(string, "\\");
System.err.println("path路:"+path);
//读取到Excel 文件名称
File importFile=new File(path);
Workbook wb=null;
try {
wb = Workbook.getWorkbook(importFile);
} catch (Exception e) {
System.err.println("出错了");
e.printStackTrace();
}
Sheet sheet[]=wb.getSheets();
int sheet_i_num=0;
if(sheet!=null &&sheet.length>0){
for(int sheetnum=0;sheetnum<sheet.length;sheetnum++){
sheet_i_num=sheet[sheetnum].getRows();
for (int rownum = 1; rownum < sheet_i_num; rownum++) {
//Cell []cells=new Cell[24];
Cell [] cells=sheet[sheetnum].getRow(rownum);
if(cells.length<24){//以防最后几各数据全部为空
for (int i = 0; i < 24-cells.length; i++) {
//cells.
}
}
String value[]=new String [24];
for (int i = 0; i < cells.length; i++) {
value[i]=cells[i].getContents();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics