pptx-ts/html
Reproduce an existing HTML <table> as a PowerPoint table, as a free function that works anywhere there is a DOM.
The same conversion is available as PptxTs.prototype.tableToSlides(id, options) on the browser build. Reach for that when you are in a browser and have a table id; reach for this when either of those is not true:
- You are not in a browser. Node has no global
document, so the method's entry point does not exist. Pass the element itself (from any DOM implementation) and no global is consulted at all; pass an id together withoptions.documentand the id resolves against that document. - You already have the element. Passing it skips the id lookup, and skips the class of bug where an id that is not a valid CSS identifier resolves to nothing.
- Your presentation is not a
PptxTs. Thepptxparameter is structural (TableToSlidesHost:addSlide+presLayout), so anything shaped like a presentation works, including the Node build.
Column widths need a layout engine. In a browser the columns are sized from each cell's rendered offsetWidth, which reproduces the table's real proportions. Nothing outside a browser lays a table out, so offsetWidth is 0 there and the conversion falls back: it uses the computed CSS widths when the stylesheet states them for every column in one unit, and an equal split when it does not. A fallback and not a graceful loss of precision: offsetWidth is the border box and computed width the content box, so padding alone can put the two bases in different proportions and the same table can come out with different column widths on either side of a layout engine. To pin widths regardless, put data-pptx-width (exact inches) or data-pptx-min-width (a floor) on the cells of the table's first row. Those win outright on every path. On a cell that spans, the value is the cell's width and divides across the columns it covers, the same way a measured or CSS width does.
Everything else (cell text with <br> preserved as a line break, colspan/rowspan, computed colors, weight, alignment, padding, borders, and auto-paging across as many slides as the rows need) works the same wherever it runs.
Example
ts
import { PptxTs } from 'pptx-ts'
import { tableToSlides } from 'pptx-ts/html'
import { Window } from 'happy-dom'
const win = new Window()
win.document.body.innerHTML = '<table id="report">…</table>'
const pptx = new PptxTs()
tableToSlides(pptx, win.document.getElementById('report'), { autoPage: true })
await pptx.writeFile({ fileName: 'report.pptx' })Type Aliases
Functions
References
Diagnostic
Re-exports Diagnostic
DiagnosticCode
Re-exports DiagnosticCode
DiagnosticHandler
Re-exports DiagnosticHandler
ErrorCode
Re-exports ErrorCode
InternalError
Re-exports InternalError
InternalErrorCode
Re-exports InternalErrorCode
InvalidOptionError
Re-exports InvalidOptionError
InvalidOptionErrorCode
Re-exports InvalidOptionErrorCode
MediaError
Re-exports MediaError
MediaErrorCode
Re-exports MediaErrorCode
PackageReadError
Re-exports PackageReadError
PackageReadErrorCode
Re-exports PackageReadErrorCode
PptxTsCode
Re-exports PptxTsCode
PptxTsError
Re-exports PptxTsError
PptxTsErrorOptions
Re-exports PptxTsErrorOptions
resetDiagnosticState
Re-exports resetDiagnosticState
setDiagnosticHandler
Re-exports setDiagnosticHandler
TableToSlidesDocument
Re-exports TableToSlidesDocument
TableToSlidesElement
Re-exports TableToSlidesElement
TableToSlidesProps
Re-exports TableToSlidesProps
TsPptxCode
Re-exports TsPptxCode
TsPptxError
Re-exports TsPptxError
TsPptxErrorOptions
Re-exports TsPptxErrorOptions
UnsupportedFeatureError
Re-exports UnsupportedFeatureError
UnsupportedFeatureErrorCode
Re-exports UnsupportedFeatureErrorCode