java匯入excel模板例子

2021-09-05 12:43:29 字數 3879 閱讀 6674

controller層

/*** 匯入excel模板

}

service層

public mapimportmoban(file file,activitiesbean bean);

serviceimpl層

@override

public mapimportmoban(file uploadfile,activitiesbean bean) catch (exception ex)

numberformat numberformat = numberformat.getinstance();// 建立乙個數值格式化物件

numberformat.setmaximumfractiondigits(2);// 設定精確到小數點後2位

for (int numsheet = 0; numsheet < workbook.getnumberofsheets(); numsheet++)

//標題行

row titlerow = sheet.getrow(1);

// 迴圈行row

for (int rownum = 4; rownum <= sheet.getlastrownum(); rownum++)

activitiesbean activitiesbean = new activitiesbean();

//讀取編號

string committee = excelutil.getcellvalue(row.getcell(0)).replaceall(" ", "");

if (null != committee && !"".equals(committee))

//讀取姓名

string committeename = excelutil.getcellvalue(row.getcell(1)).replaceall(" ", "");

if (null != committeename && !"".equals(committeename))

//讀取會議應參加

string mettingshoublebe = excelutil.getcellvalue(row.getcell(2)).replaceall(" ", "");

if (null != mettingshoublebe && !"".equals(mettingshoublebe))

//讀取會議實參加

string mettingtruebe = excelutil.getcellvalue(row.getcell(3)).replaceall(" ", "");

if (null != mettingtruebe && !"".equals(mettingtruebe))

//讀取會議參加率

//string mettingrate = excelutil.numofimport(row.getcell(4)).replaceall(" ", "");

if (null != mettingtruebe && !"".equals(mettingtruebe) && null != mettingshoublebe && !"".equals(mettingshoublebe))

//讀取調研應參加

string researchshoublebe = excelutil.getcellvalue(row.getcell(5)).replaceall(" ", "");

if (null != researchshoublebe && !"".equals(researchshoublebe))

//讀取調研實參加

string researchtruebe = excelutil.getcellvalue(row.getcell(6)).replaceall(" ", "");

if (null != researchtruebe && !"".equals(researchtruebe))

//讀取調研參加率

//string researchrate = excelutil.numofimport(row.getcell(7)).replaceall(" ", "");

if (null != researchtruebe && !"".equals(researchtruebe) && null != researchshoublebe && !"".equals(researchshoublebe))

//讀取其他活動應參加othershoublebe

string othershoublebe = excelutil.getcellvalue(row.getcell(8)).replaceall(" ", "");

if (null != othershoublebe && !"".equals(othershoublebe))

//讀取其他活動實參加

string othertruebe = excelutil.getcellvalue(row.getcell(9)).replaceall(" ", "");

if (null != othertruebe && !"".equals(othertruebe))

//讀取其他活動參加率

//string otherrate = excelutil.numofimport(row.getcell(10)).replaceall(" ", "");

if (null != othertruebe && !"".equals(othertruebe) && null != othershoublebe && !"".equals(othershoublebe))

//讀取備註

string remark = excelutil.getcellvalue(row.getcell(11)).replaceall(" ", "");

if (null != remark && !"".equals(remark))

if((activitiesbean.getcommitteename())!=null && !"".equals((activitiesbean.getcommitteename())))}}

// 返回excel資料不合格的行數

int successrow = 0;// 成功條數

if (null != planlist && planlist.size() > 0)

}else

filetool.delfile(uploadfile);// 刪除臨時目錄下的excel檔案

resultmap.put("returnmess", "成功匯入資料(共" + successrow + "條)!");

return resultmap;

} catch (exception e)

}

/**

* 刪除已經存在的檔案

* * @param filepathandname

* 檔案存放路徑

如何匯入Excel模板

第乙個引數是檔案的名字,第二個引數是檔案的路徑,是否需要刪除 當我點選瀏覽,上傳填寫完資料的excel文件,此時匯入資料的按鈕也可以進行提交,如果需要哪些資料,就選擇核取方塊進行勾選即可 當選擇乙個檔案的時候 當點選匯入按鈕的時候 protected void importexcel click o...

java批量匯入Excel

util包 public class excelhelp catch exception ex for int numsheet 0 numsheet workbook.getnumberofsheets numsheet 迴圈行row for int rownum 1 rownum sheet.g...

DBGird中資料匯入Excel例子!

procedure tform1.bitbtn1click sender tobject varexcelworksheet texcelworksheet excelworkbook texcelworkbook i,row,column integer x1,x2,y1,y2 integer b...