We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码示例:
// ### get excel const ExcelJS = require('exceljs'); const archiver = require('archiver'); const path = require('path'); const fs = require('fs'); /** * 获取excel 内容 * @returns {Promise<ExcelJS.Workbook>} */ async function getExcel() { let now = new Date(); let sheet_name = `export(${now.toDateString()})`; const workbook = new ExcelJS.Workbook(); workbook.creator = 'Me'; workbook.lastModifiedBy = 'Her'; workbook.created = now; workbook.modified = now; workbook.lastPrinted = now; workbook.addWorksheet(sheet_name, {}); return workbook; } /** * 保存excel * @param {*} excelDir excel 位置 * @param {*} workbook excel 内容 * @param {string} excelName excel 名称 * @returns */ async function storeExcel(excelDir, workbook, excelName = 'test.xlsx') { let fpath = path.join(excelDir, excelName); workbook.worksheets[0].views = [ { state: 'frozen', xSplit: 1, ySplit: 1, topLeftCell: 'A1', activeCell: 'A1' } ]; await workbook.xlsx.writeFile(fpath).catch(err => console.error(err)); return fpath; } async function createZip(excelDir) { const output = fs.createWriteStream(__dirname + '/example.zip'); const archive = archiver('zip', { zlib: { level: 9 } }); archive.pipe(output); let excelBuffer = await fs.promises.readFile(excelDir); if (excelBuffer) { const excelName = path.basename(excelDir) archive.append(excelBuffer, { name: excelName }); } await archive.finalize(); } async function test() { let workbook = await getExcel(); let store_dir = __dirname; let excelPath = await storeExcel(store_dir, workbook); console.log('excelPath :>>', excelPath) await createZip(excelPath) } test()
结果如图: 压缩后修改时间不是源文件修改时间,也不是中国时区当前时间
The text was updated successfully, but these errors were encountered:
No branches or pull requests
代码示例:
结果如图:
压缩后修改时间不是源文件修改时间,也不是中国时区当前时间
The text was updated successfully, but these errors were encountered: