生成npm里面的xlsxjs导出代码xlsx表的内容是这样的:其中新生可期-复发套细胞淋巴瘤患者援助项目项目为标题独占一行居中加粗配送捐赠药物说明书为副标题独占一行居中加粗。第三行为接收药房:独占一行第四行为接收地址:独占一行第五行为配送单号:和装箱时间: 两个各一半成一行第六行为药品名称、药品规格、药品规格、药品批号、有效期、数量这五个成一行从第三行到第六行每个文字都是靠左显示要给它加黑色边框
const XLSX = require('xlsx');
const data = [ ['新生可期-复发套细胞淋巴瘤患者援助项目项目'], ['配送捐赠药物说明书'], ['接收药房:'], ['接收地址:'], ['配送单号:', '', '', '装箱时间:'], ['药品名称', '药品规格', '药品规格', '药品批号', '有效期', '数量'], ];
const ws = XLSX.utils.aoa_to_sheet(data); ws['!cols'] = [{ width: 20 }, { width: 20 }, { width: 20 }, { width: 20 }, { width: 20 }, { width: 20 }]; ws['!rows'] = [{ hpt: 30, hpx: 30 }, { hpt: 30, hpx: 30 }, { hpt: 30, hpx: 30 }, { hpt: 30, hpx: 30 }, { hpt: 30, hpx: 30 }, { hpt: 20, hpx: 20 }];
const range = XLSX.utils.decode_range(ws['!ref']); for (let R = range.s.r; R <= range.e.r; ++R) { for (let C = range.s.c; C <= range.e.c; ++C) { const cell = XLSX.utils.encode_cell({ r: R, c: C }); ws[cell].s = { border: { top: { style: 'thin', color: { auto: 1 } }, right: { style: 'thin', color: { auto: 1 } }, bottom: { style: 'thin', color: { auto: 1 } }, left: { style: 'thin', color: { auto: 1 } } }, font: { name: '宋体', sz: 9 }, alignment: { horizontal: 'left', vertical: 'center' } }; if (R === 0 || R === 1) { ws[cell].s.font.bold = true; ws[cell].s.alignment.horizontal = 'center'; } } }
const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, 'Sheet1'); XLSX.writeFile(wb, 'example.xlsx')
原文地址: https://www.cveoy.top/t/topic/fuWA 著作权归作者所有。请勿转载和采集!