基於xlsx excel 匯入功能

2021-09-24 11:05:01 字數 2138 閱讀 5528

import xlsx from 'xlsx';

const digit_regex = /^[0-9]*$/;

const name_regex = /^[\u4e00-\u9fa5]$/;

const date_regex = /^\d-\d-\d$/;

const phone_regex = /^1[3|4|5|7|8][0-9]$/;

const email_regex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;

/** * xlsx 方式匯入

* @param e 所選檔案

* @param headermap [key => value| 中文 => pojo屬性]

* @param handlerescallback 處理結果集[驗證資料合法性]

* @param errorcallback 處理異常

*/function importexcel(e, headermap, handlerescallback, errorcallback) = e.target;

if (!files) return;

const file = files[0];

const filereader = new filereader();

filereader.readasbinarystring(file);

filereader.onload = event => = event.target;

const wb = xlsx.read(result, );

let res = ;

for (const sheet in wb.sheets)

}});

res = res.concat(data);}}

handlerescallback(res);

} catch (e)

};}/**

* 數字校驗

* @param value

* @returns

*/function digitvalitor(value)

return true;

}/**

* 名稱校驗

* @param value

* @returns

*/function namevalitor(value)

return true;

}/**

* 日期格式校驗

* @param value

* @returns

*/function datevalitor(value)

return true;

}/**

* **號碼校驗

* @param value

* @returns

*/function phonevalitor(value)

return true;

}/**

* 郵箱校驗

* @param value

* @returns

*/function emailvalitor(value)

return true;

}export default ;

import react,  from 'react';

import excelutil from './excelutil';

class users extends component

}componentdidmount()

callback = (res) =>

}if (key == 'age')

}if (key == 'birthday') }}

});console.log("匯入成功...");

Excel匯入功能

匯入excel內容 首先批量插入資訊 boolean f service.insertxzxk m 查出資訊。list listall service.queryxzxklist m,false 對比兩個list excel中的資料在list存在表示成功,不存在表示失敗,失敗的放到error裡面 l...

idea 匯入功能

listeivos new arraylist 10 string item boolean issuccess true listbeanlist new arraylist 10 mstallofigureconfig bean null hashmapresult new hashmap 1 ...

Excel的匯入功能

專案中使用到了excel的匯入功能,趕了兩天終於可以跑起來了,下面寫下實現的具體思路 大家都知道,poi是很好用的讀取excel檔案的技術,而且只需匯入乙個jar檔案即可,非常的方便 學習起來也特別的容易,網上這方面的資料非常多。具體的應用網上都有現成的demo。其實要是技術上的難點,應該算是也實現...