Skip to content

Instantly share code, notes, and snippets.

@Houserqu
Created May 5, 2021 01:32
Show Gist options
  • Save Houserqu/6557f8159d16ee052f106f8e7bec4c5b to your computer and use it in GitHub Desktop.
Save Houserqu/6557f8159d16ee052f106f8e7bec4c5b to your computer and use it in GitHub Desktop.
js-xlsx
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'
})
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