Gathering detailed insights and metrics for html-docx-js-extends
Gathering detailed insights and metrics for html-docx-js-extends
npm install html-docx-js-extends
Typescript
Module System
Node Version
NPM Version
71.1
Supply Chain
93.4
Quality
75.9
Maintenance
100
Vulnerability
99.6
License
Total Downloads
1,317
Last Day
4
Last Week
24
Last Month
71
Last Year
1,263
Minified
Minified + Gzipped
Latest Version
0.1.8
Package Id
html-docx-js-extends@0.1.8
Unpacked Size
86.25 kB
Size
18.09 kB
File Count
63
NPM Version
9.8.0
Node Version
16.13.1
Publised On
22 Jun 2024
Cumulative downloads
Total Downloads
Last day
0%
4
Compared to previous day
Last week
50%
24
Compared to previous week
Last month
-19.3%
71
Compared to previous month
Last year
2,238.9%
1,263
Compared to previous year
[![NPM version][npm-image]][npm-url]
基于 html-docx-js 进行了功能扩展.
在原始库支持将HTML内容转换为docx格式文件的基础上,扩展支持了对单个章节纵横方向的设置。
npm install html-docx-js-extends --save-dev
支持node.js运行环境和纯浏览器环境, 包括vue/react/angular等前端框架.
1import { asBlob } from 'html-docx-js-extends' 2// if you want to save the docx file, you need import 'file-saver' 3import { saveAs } from 'file-saver' 4 5const htmlString = `<!DOCTYPE html> 6<html lang="en"> 7<head> 8 <meta charset="UTF-8"> 9 <title>Document</title> 10</head> 11<body> 12 <h1>Welcome</h1> 13</body> 14</html>` 15 16export default { 17 methods: { 18 saveDocx() { 19 asBlob(htmlString).then(data => { 20 saveAs(data, 'file.docx') // save as docx file 21 }) // asBlob() return Promise<Blob|Buffer> 22 }, 23 }, 24}
可以使用 options 参数(包括margins 和 orientation)
1const data = await asBlob(htmlString, { orientation: 'landscape', margins: { top: 100 } })
If you use this package in a Typescript file and declare the options to an independent Object
like:
1import { asBlob } from 'html-docx-js-extends' 2const opt = { 3 margin: { 4 top: 100 5 }, 6 orientation: 'landscape' // type error: because typescript automatically widen this type to 'string' but not 'Orient' - 'string literal type' 7} 8await asBlob(html, opt)
You can use as const
to avoid type widening.
1const opt = { 2 margin: { 3 top: 100 4 }, 5 orientation: 'landscape' as const 6}
多节点导出
1 const wordFile = createWord('报表')
2 wordFile.addSection(HTML_CASE_3, { orientation: 'landscape', margins: { left: 720, right: 720 } })
3 wordFile.addSection(HTML_CASE, { orientation: 'portrait', margins: { left: 720, right: 720 } })
4 wordFile.addSection(HTML_CASE_2, { orientation: 'landscape', margins: { left: 720, right: 720 } })
5
6 let blobRes = wordFile.asBlob().then(blob => {
7 saveAs(blob, wordFile.fileName || '导出.doc');
8 });
No vulnerabilities found.
No security vulnerabilities found.