function sheet_from_array_of_arrays(data) {
for (let R = 0; R !== data.length; ++R) {
for (let C = 0; C !== data[R].length; ++C) {
if (range.s.r > R) range.s.r = R
if (range.s.c > C) range.s.c = C
if (range.e.r < R) range.e.r = R
if (range.e.c < C) range.e.c = C
if (cell.v === null) continue
const cell_ref = XLSX.utils.encode_cell({
if (typeof cell.v === 'number') cell.t = 'n'
else if (typeof cell.v === 'boolean') cell.t = 'b'
else if (cell.v instanceof Date) {
cell.z = XLSX.SSF._table[14]
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range)
if (!(this instanceof Workbook)) return new Workbook()
const buf = new ArrayBuffer(s.length)
const view = new Uint8Array(buf)
for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff
export function export_json_to_excel({
filename = filename || 'excel-list'
for (let i = multiHeader.length - 1; i > -1; i--) {
data.unshift(multiHeader[i])
const ws_name = 'SheetJS'
const wb = new Workbook()
const ws = sheet_from_array_of_arrays(data)
if (!ws['!merges']) ws['!merges'] = []
merges.forEach((item) => {
ws['!merges'].push(XLSX.utils.decode_range(item))
const colWidth = data.map((row) =>
/* 先判断是否为null/undefined*/
} else if (val.toString().charCodeAt(0) > 255) {
wch: val.toString().length * 3
wch: val.toString().length + 10
const result = colWidth[0]
for (let i = 1; i < colWidth.length; i++) {
for (let j = 0; j < colWidth[i].length; j++) {
if (result[j].wch < colWidth[i][j].wch) {
result[j].wch = colWidth[i][j].wch
/* add worksheet to workbook */
wb.SheetNames.push(ws_name)
const wbout = XLSX.write(wb, {
new Blob([s2ab(wbout)], {
type: 'application/octet-stream'
`${filename}.${bookType}`
function formatJson(filterVal, jsonData) {
return jsonData.map((v) =>