iView匯入Excel資料到資料庫

2021-08-13 02:30:18 字數 2836 閱讀 5797

1.前端使用的是iview的upload上傳元件

2.後端使用的是excelpackage,當然可以使用npoi

3.效果圖:

後端**如下:

1)

//匯入

int rowcounr = (int)math.ceiling((decimal)((decimal)worksheet.cells.count() / 8));//所有**數 / 列數 = 行數

listlst = new list();

pubpopertyservice svc = new pubpopertyservice();

#region

for (int i = 2; i <= rowcounr; i++)

if (worksheet.cells[i, 2].value.tostring().length > 32)

if (string.isnullorwhitespace(worksheet.cells[i, 3].value.tostring()))

if (worksheet.cells[i, 3].value.tostring().length > 128)

if (string.isnullorwhitespace(worksheet.cells[i, 4].value.tostring()))

if (worksheet.cells[i, 4].value.tostring().length > 8)

if (worksheet.cells[i, 5].value == null)

if (decimal.parse(worksheet.cells[i, 5].value.tostring()) < 1 || decimal.parse(worksheet.cells[i, 5].value.tostring()) > 999999999999)

if (worksheet.cells[i, 6].value == null)

if (decimal.parse(worksheet.cells[i, 6].value.tostring()) < 1 || decimal.parse(worksheet.cells[i, 6].value.tostring()) > 999999999999)

if (worksheet.cells[i, 7].value == null)

if (decimal.parse(worksheet.cells[i, 7].value.tostring()) < 1 || decimal.parse(worksheet.cells[i, 7].value.tostring()) > 999999999999)

if (worksheet.cells[i, 8].value == null)

if (worksheet.cells[i, 8].value.tostring().length != 7)

entity.propname = worksheet.cells[i, 2].value.tostring();

entity.address = worksheet.cells[i, 3].value.tostring();

entity.legalusage = worksheet.cells[i, 4].value.tostring();

entity.area = decimal.parse(worksheet.cells[i, 5].value.tostring());

entity.floorarea = decimal.parse(worksheet.cells[i, 6].value.tostring());

entity.housetotal = int.parse(worksheet.cells[i, 7].value.tostring());

entity.builtyear = datetime.parse(worksheet.cells[i, 8].value.tostring());

entity.creator = current.id;

entity.creatorname = current.name;

entity.created = datetime.now;

entity.updator = current.id;

entity.updatorname = current.name;

entity.updated = datetime.now;

entity.status = 3;

entity.govid = current.govid;

lst.add(entity);

int id = 0;

svc.create(entity, out id);

result.code = 1;

}#endregion}}

catch (exception ex)

().異常為:", current.name, current.id,ex);

result.msg = new erroritem(1027, "匯入轄區物業資訊失敗").tostring();

}return json(result);

}

前端**如下:1)

導  入

Excel資料匯入到Grid

方法一 string strcon provider microsoft.jet.oledb.4.0 data source strsource extended properties excel 8.0 string query select from sheet1 sheet1表示表 oledb...

Excel資料匯入到Access

下面是asp的全部程式,需要做的是建乙個test.mdb資料庫和乙個test.xls的excel 查詢excel準備匯入到access sql select from sheet1 要匯入的excel資料裡面的表的名稱,後面一定要加 set rs conn2.execute sql while no...

Excel資料匯入到oracle

excel資料匯入到oracle 第一步 將要匯入的excel檔案開啟,選擇 另存為 在檔案型別那裡選擇 文字.txt 後確定儲存 第二步 開啟記事本,編寫下列的內容 注釋 1 控制檔案標識 2 剛才由excel檔案轉化過來的檔案的路徑 3 向oracle的資料表t network agent ba...