SheetJS,修复的记录:从/xl/workbook.xml部分(工作簿)的工作表属性

By simon at 2018-02-07 • 0人收藏 • 309人看过

我使用[SheetJS](https://github.com/SheetJS/js-xlsx)将数据导出到excel 看起来像是excel本身修复数据。数据下载广告不错,但可以 收到此警告?我已经从UI和file.xlsx,当我打开它通过 我收到了一些警告ing由Excel自己生成。 ![screenshot5(https://开头用户 images.githubusercontent.com/14881178/35859418-a902a4f4-0b48-11e8-96cf- 070f0d6c9b7e.png)![screenshot4](https:// user- images.githubusercontent.com/14881178/35859419-a91f0324-0b48-11e8-84d5-7b7e050138cb.png) 码:

const download = (url, name) => {
    let a = document.createElement('a')
    a.href = url
    a.download = name
    a.click()

    window.URL.revokeObjectURL(url)
}

function Workbook() {
    if (!(this instanceof Workbook))
        return new Workbook()

    this.SheetNames = []

    this.Sheets = {}
}

function s2ab(s) {
    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

    return view
}

export default data => {
    import('xlsx').then(XLSX => {
        const wb = new Workbook()
        const ws = XLSX.utils.json_to_sheet(data)

        wb.SheetNames.push('s')
        wb.Sheets[''] = ws

        const wbout = XLSX.write(wb, {bookType:'xlsx', bookSST:true, type: 'binary'})

        let url = window.URL.createObjectURL(new Blob([s2ab(wbout)], {type:'application/octet-stream'}))

        download(url, 'import.xlsx')
    })
}

1 个回复 | 最后更新于 2018-02-07
2018-02-07   #1

我是显而易见的问题,为了解决这个问题,我设置了:

 const wbSheetNames = 'Custom Name'
        wb.SheetNames.push(wbSheetNames)
        wb.Sheets[wbSheetNames] = ws

登录后方可回帖

Loading...