How to use the html-to-xlsx.XlsxPopulate.fromDataAsync function in html-to-xlsx

To help you get started, we’ve selected a few html-to-xlsx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsreport / jsreport-html-to-xlsx / lib / mergeXlsx.js View on Github external
shortid: request.template.baseXlsxTemplate.shortid
    }, request)

    if (!docs.length) {
      throw reporter.createError(`Unable to find xlsx template with shortid ${request.template.baseXlsxTemplate.shortid}`, {
        statusCode: 404
      })
    }

    xlsxTemplateBuf = docs[0].contentRaw
  }

  tableXlsxBuf = Buffer.concat(await toArrayAsync(response.stream))

  const [templateWorkbook, tableWorkbook] = await Promise.all([
    XlsxPopulate.fromDataAsync(xlsxTemplateBuf),
    XlsxPopulate.fromDataAsync(tableXlsxBuf)
  ])

  const sheetsInTableWorkbook = tableWorkbook.sheets()

  sheetsInTableWorkbook.forEach((sheet) => {
    let oldSheet

    if (templateWorkbook.sheet(sheet.name()) != null) {
      if (templateWorkbook.sheets().length === 1) {
        oldSheet = `${sheet.name()}-old`
        // the workbook can not have empty sheets so we need to rename the only sheet first and then delete it
        templateWorkbook.sheet(sheet.name()).name(oldSheet)
      } else {
        templateWorkbook.deleteSheet(sheet.name())
      }
github jsreport / jsreport-html-to-xlsx / lib / mergeXlsx.js View on Github external
}, request)

    if (!docs.length) {
      throw reporter.createError(`Unable to find xlsx template with shortid ${request.template.baseXlsxTemplate.shortid}`, {
        statusCode: 404
      })
    }

    xlsxTemplateBuf = docs[0].contentRaw
  }

  tableXlsxBuf = Buffer.concat(await toArrayAsync(response.stream))

  const [templateWorkbook, tableWorkbook] = await Promise.all([
    XlsxPopulate.fromDataAsync(xlsxTemplateBuf),
    XlsxPopulate.fromDataAsync(tableXlsxBuf)
  ])

  const sheetsInTableWorkbook = tableWorkbook.sheets()

  sheetsInTableWorkbook.forEach((sheet) => {
    let oldSheet

    if (templateWorkbook.sheet(sheet.name()) != null) {
      if (templateWorkbook.sheets().length === 1) {
        oldSheet = `${sheet.name()}-old`
        // the workbook can not have empty sheets so we need to rename the only sheet first and then delete it
        templateWorkbook.sheet(sheet.name()).name(oldSheet)
      } else {
        templateWorkbook.deleteSheet(sheet.name())
      }
    }

html-to-xlsx

Convert html to xlsx

MIT
Latest version published 2 months ago

Package Health Score

66 / 100
Full package analysis