Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
html-to-xlsx
Advanced tools
node.js html to xlsx transformation
Transformation only supports html table and several basic style properties. No images or charts are currently supported.
const util = require('util')
const fs = require('fs')
const conversionFactory = require('html-to-xlsx')
const puppeteer = require('puppeteer')
const chromeEval = require('chrome-page-eval')({ puppeteer })
const writeFileAsync = util.promisify(fs.writeFile)
const conversion = conversionFactory({
extract: async ({ html, ...restOptions }) => {
const tmpHtmlPath = path.join('/path/to/temp', 'input.html')
await writeFileAsync(tmpHtmlPath, html)
const result = await chromeEval({
...restOptions,
html: tmpHtmlPath,
scriptFn: conversionFactory.getScriptFn()
})
const tables = Array.isArray(result) ? result : [result]
return tables.map((table) => ({
name: table.name,
getRows: async (rowCb) => {
table.rows.forEach((row) => {
rowCb(row)
})
},
rowsCount: table.rows.length
}))
}
})
async function run () {
const stream = await conversion(`<table><tr><td>cell value</td></tr></table>`)
stream.pipe(fs.createWriteStream('/path/to/output.xlsx'))
}
run()
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 to scroll
or auto
.const conversionFactory = require('html-to-xlsx')
const puppeteer = require('puppeteer')
const chromeEval = require('chrome-page-eval')({ puppeteer })
const conversion = conversionFactory({ /*[constructor options here]*/})
extract
function [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*/
}
tmpDir
string - the directory path that the module is going to use to save temporary files needed during the conversion. defaults to require('os').tmpdir()
timeout
number - time in ms to wait for the conversion to complete, when the timeout is reached the conversion is cancelled. defaults to 10000
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: async ({ html, ...restOptions }) => {
const tmpHtmlPath = path.join('/path/to/temp', 'input.html')
await writeFileAsync(tmpHtmlPath, html)
const result = await chromeEval({
...restOptions,
html: tmpHtmlPath,
scriptFn: conversionFactory.getScriptFn()
})
const tables = Array.isArray(result) ? result : [result]
return tables.map((table) => ({
name: table.name,
getRows: async (rowCb) => {
table.rows.forEach((row) => {
rowCb(row)
})
},
rowsCount: table.rows.length
}))
}
})
async function main () {
const stream = await conversion(/* html */, /* extract options */)
}
main()
html
string - the html source that will be transformed to an xlsx, the html should contain a table elementextractOptions
object - additional options to pass to the specified extract
functionSee license
FAQs
Convert html to xlsx
The npm package html-to-xlsx receives a total of 1,720 weekly downloads. As such, html-to-xlsx popularity was classified as popular.
We found that html-to-xlsx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.