POI讀取資料,存入資料庫中

2021-10-07 00:16:39 字數 1433 閱讀 7201

以這樣的office**為資料來源,poi處理資料,讀取表中資料,並寫入資料庫,並對當中存在空行的資料給出友好提示。

office主要有03 和 07版本,區別不是很大。

org.apache.poi

poi3.9

org.apache.poi

poi-ooxml

3.9

public class edusubjectcontroller  else }}

//匯入課程分類

@override

public list importdata(multipartfile file)

//6 獲取第一列資料(一級分類)

string cellonevalue = cellone.getstringcellvalue();

if(stringutils.isempty(cellonevalue))

//定義變數,用於儲存一級分類id

string pid = null;

//新增一級分類到資料庫中,把parent_id設定為0

//判斷表是否存在相同的一級分類

edusubject oneedusubject = this.existonesubject(cellonevalue);

if(oneedusubject == null) else

//獲取第二列

cell celltwo = row.getcell(1);

//判斷列是否為空

if(celltwo == null)

//獲取第二列資料

string celltwovalue = celltwo.getstringcellvalue();

//判斷列是否為空

if(stringutils.isempty(celltwovalue))

//判斷表是否存在相同的二級分類,如果沒有新增

edusubject twoedusubject = this.existtwosubject(celltwovalue, pid);

if(twoedusubject == null)

}return msg;

}catch(exception e)

}// 判斷表是否存在相同的二級分類,如果沒有新增

private edusubject existtwosubject(string twosubjectname,string pid)

//判斷分類表是否存在相同的一級分類

private edusubject existonesubject(string onesubjectname)

}

POI讀取Excel到資料庫

新入職後,接手的第乙個任務是將excel中的資料錄入資料庫,這裡總結一下。public string excelinput throws exception 迴圈行row for int rownum 1 rownum xssfsheet.getlastrownum rownum 1,對於類似 號碼...

numpy 資料型別存入資料庫中

import numpy as np import pymysql prediction np.array mysql server localhost name root password your password mysql db your database db pymysql.connec...

excel表資料存入資料庫

參考 實現 public string add httpservletrequest request,httpservletresponse response else if file.matches i xlsx sheet sheet workbook.getsheetat 0 sheet 從0...