Package Exports
- html-to-xlsx
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-to-xlsx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
html-to-xlsx
node.js html to xlsx transformation
Transformation only supports html table and several basic style properties. No images or charts are currently supported.
Usage
const fs = require('fs')
const conversionFactory = require('html-to-xlsx')
const puppeteer = require('puppeteer')
const chromeEval = require('chrome-page-eval')({ puppeteer })
const conversion = conversionFactory({
extract: chromeEval
})
async function run () {
const stream = await conversion(`<table><tr><td>cell value</td></tr></table>`)
stream.pipe(fs.createWriteStream('/path/to/output.xlsx'))
}
run()Supported properties
background-color- cell background colorcolor- cell foreground colorborder-left-style- as well as positions will be transformed into excel cells borderstext-align- text horizontal align in the excel cellvertical-align- vertical align in the excel cellwidth- the excel column will get the highest width, it can be little bit inaccurate because of pixel to excel points conversionheight- the excel row will get the highest heightfont-size- font sizecolspan- numeric value that merges current column with columns to the rightrowspan- numeric value that merges current row with rows below.overflow- the excel cell will have text wrap enabled if this is set toscrollorauto.
Constructor options
const conversionFactory = require('html-to-xlsx')
const puppeteer = require('puppeteer')
const chromeEval = require('chrome-page-eval')({ puppeteer })
const conversion = conversionFactory({ /*[constructor options here]*/})extractfunction [required] - a function that receives some input (an html file path and a script) and should return some data after been evaluated the html passed. the input that the function receives is:{ html: <file path to a html file>, scriptFn: <string that contains a javascript function to evaluate in the html>, timeout: <time in ms to wait for the function to complete, the function should use this value to abort any execution when the time has passed>, /*options passed to `conversion` will be propagated to the input of this function too*/ }
tmpDirstring - the directory path that the module is going to use to save temporary files needed during the conversion. defaults torequire('os').tmpdir()timeoutnumber - time in ms to wait for the conversion to complete, when the timeout is reached the conversion is cancelled. defaults to10000
Conversion options
const fs = require('fs')
const conversionFactory = require('html-to-xlsx')
const puppeteer = require('puppeteer')
const chromeEval = require('chrome-page-eval')({ puppeteer })
const conversion = conversionFactory({
extract: chromeEval
})
async function main () {
const stream = await conversion(/* html */, /* extract options */)
}
main()htmlstring - the html source that will be transformed to an xlsx, the html should contain a table elementextractOptionsobject - additional options to pass to the specifiedextractfunction
License
See license
