javaWeb poi匯入excel檔案

2021-07-10 08:33:27 字數 3969 閱讀 5226

/**

* execl資料格式的轉換

* * @param cell

* @return

*/public string publicexcel(cell cell)

return value;

}/***

* * 取得workbook物件(xls和xlsx物件不同,不過都是workbook的實現類)

*   xls:hssfworkbook

*   xlsx:xssfworkbook

* @param filepath

* @return

* @throws ioexception

* @author fangke

*/private workbook getworkbook(string filepath,string filename) throws ioexception else if (filename.endswith("xlsx"))

return workbook;

}/**

* 該方法是利用poi對匯入的excel,進去解析讀取和寫入資料庫

* @param filename

* @param filepath

* @throws exception

* @author fangke

*/public void importexcel(string filename, string filepath) throws exception

row row = childsheet.getrow(rowi);

// int firstcolumnindex = row.getfirstcellnum(); // 首列

// int lastcolumnindex = row.getlastcellnum();// 最後一列

// for (int columnindex = firstcolumnindex; columnindex

// <= lastcolumnindex; columnindex++)

// //讀取一行資料,從0開始,0代表第乙個單元格內容

string id = uuid.randomuuid().tostring().replace("-", "");// id

//新增時設定倉庫資訊

iuser user = this.getiuser();

string wahid = null;

arraylist items = this.myexesql("select a.f_wah_id from t_itm_wa_house a where a.f_dept_own='" + user.getorgid() + "'");

for (int j = 0; j < items.size(); j++)

string devcode = "zcbh-" + creatorder.getorderno();// 編碼

string devname = this.publicexcel(row.getcell(1));// 分類名稱

string proptype = this.publicexcel(row.getcell(2));//資產型別

if("主裝置".equals(proptype))else if("配件".equals(proptype))else if("介質".equals(proptype))

string classvalid = "0"; // 是否分類有效 0代表不是分類

string parentid = null;

string levelcode = null;

arraylist items1 = this.myexesql("select t.f_parent_id,t.f_level_code from t_itm_material t where t.f_dev_name='"+devname+"' and t.f_class_valid=1");

for (int j = 0; j < items1.size(); j++)

string isclassify = "0"; //是否為資產分類 0代表為資產

string devspec = this.publicexcel(row.getcell(5));//型號

string deptown = user.getorgid();//單位id

string devnuit = this.publicexcel(row.getcell(6));// 計量單位 0-臺,1-套,2-個

if("臺".equals(devnuit))else if("套".equals(devnuit))else if("個".equals(devnuit))

string devstatus = this.publicexcel(row.getcell(9));//現存狀態 0-閒置  1-在用 

if("閒置".equals(devstatus) && !"在用".equals(devstatus))else

string devattr = "0";// 資產屬性

string wasteattr = this.publicexcel(row.getcell(12));// 報廢屬性 0-正常 1-報廢

if("正常".equals(wasteattr)&&!"報廢".equals(wasteattr))else

string moneysource = this.publicexcel(row.getcell(14));//資金**

string wahstatus = this.publicexcel(row.getcell(10));// 倉庫狀態  0-在庫 1-離庫

if("離庫".equals(wahstatus)&&!"在庫".equals(wahstatus))else

string keeper = this.publicexcel(row.getcell(13));//保管人

string supply = this.publicexcel(row.getcell(15));//**商

string price = this.publicexcel(row.getcell(7));//購入原值

double pricedouble =double.parsedouble(price) ;

string timein = this.publicexcel(row.getcell(8));//購入時間

date timeindate = sdf.parse(timein);

string remark = this.publicexcel(row.getcell(17));//備註說明

string creatid = user.getuserid();//

date createtime = new date();//建立時間

string modifyid = user.getuserid();//

date modifytime = new date();//修改時間

levelcode = levelcode+"-"+id;//

string brand = this.publicexcel(row.getcell(4));//品牌

string supplyphone = this.publicexcel(row.getcell(16));//**商**

string number = "1";//數量

int numberint = integer.parseint(number);

string purpose = this.publicexcel(row.getcell(3));//裝置用途

/** 插入資料庫

*/stringbuffer sql = new stringbuffer();

int a = stmt.executeupdate(sql.tostring());

if (a < 0)}}

}conn.commit();// 插入正常

conn.close();

} catch (exception e)} }

springMVC jxl資料庫匯入Excel檔案

1.新建乙個jsp表單 用到multipart 2.controller ftpserver判斷 然後是username判斷 usegeneratedkeys true 和主鍵id對應 conroller下面的紅色 獲得主鍵 客戶名customerbean.setname pinyin.addpin...

Eas waf2框架中利用POI匯入excel

首先要確保有apache poi包然後利用上傳附件控制項發請求到後台 然後後台處理好儲存到資料庫中,注意的是apache poi包讀取的excel只能讀取excel2003以xls結尾的excel excel2007會發生識別錯誤 以下是請求方法 以下是讀取excel方法 版本 eas7.0 作者 ...

springboot JXL實現匯出excel

一.新增匯出工具類 二.controller層 匯出返傭日誌資訊,前端傳exporttype 1,2,3 或者直接寫乙個方法,只匯出一種型別 param response param record return 匯出返傭日誌資訊 三.service層 匯出返傭日誌資訊 匯出返傭日誌明細資訊 匯出返傭...