java程序导入Excel表数据

程序如下:

File file = new File("D:\\1-2.xls");
    String vehicleidiac1 = "";
    int count = 0;
    Workbook wb = null;
try {
FileInputStream fileInputStream = new FileInputStream(file);
wb = Workbook.getWorkbook(fileInputStream);
} catch (FileNotFoundException e) {
System.out.println("文件导入错误");
e.printStackTrace();
} catch (BiffException e) {
System.out.println("文件流获取错误");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    Sheet sheet = wb.getSheet(0);
    int nRow = sheet.getRows();
    int nColumn = sheet.getColumns();
    System.out.print("转化前-----------");
System.out.println("转化后");
String nhql1 = "from YWRelation";
List<YWRelation> ywRelations1 = this.findByHql(nhql1);
for(int j = 1;j < nRow; j++){
String[] rowData = new String[nColumn];
Cell[] cells = sheet.getRow(j);
for (int k = 0; k < nColumn; k++) {
 synchronized (cells[k].getContents()) {
 Boolean istrue = false;
rowData[k] = cells[k].getContents(); 
try {
String vehicleidiac1 = "";
for(YWRelation ywRelation : ywRelations1){
if(rowData[k].equals(ywRelation.getVehiclejycode().trim())){
//解码
istrue = true;
vehicleidiac1 = RuleUtils.decodeJyCode(ywRelation.getVehiclecode().trim());
if(vehicleidiac1.equals("")&&vehicleidiac1.length()==0||"BXPTYXCL9999".equals(vehicleidiac1)){
vehicleidiac1="BXPTYXCL9999";
}
logger_debug.info(rowData[k]+"   "+vehicleidiac1);
continue;
}
}
if(istrue == false){
logger_debug.info(rowData[k]+"   "+"BXPTYXCL9999");
}
} catch (Exception e) {
System.out.println("录入错误");
e.printStackTrace();
}
}
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值