Created
May 5, 2021 01:32
-
-
Save Houserqu/6557f8159d16ee052f106f8e7bec4c5b to your computer and use it in GitHub Desktop.
js-xlsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rows = [{}] | |
| let wb = XLSX.utils.book_new() | |
| let ws = XLSX.utils.aoa_to_sheet(rows) | |
| // 设置每一列宽度 | |
| ws['!cols'] = [{wpx: 120}, {wpx: 100}, {wpx: 200}, {wpx: 100}] | |
| let name = 'excel 文件' | |
| XLSX.utils.book_append_sheet(wb, ws, name) | |
| ctx.body = XLSX.write(wb, { | |
| type: 'buffer', | |
| bookType: 'xlsx' | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const file = ctx.request.files.file | |
| const workBook = XLSX.readFile(file.path) | |
| const worksheet = workBook.Sheets[workBook.SheetNames[0]] | |
| rows = XLSX.utils.sheet_to_json(worksheet, {range: 1, defval: ''}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment