# xh-htmlword **Repository Path**: sdl-code/xh-htmlword ## Basic Information - **Project Name**: xh-htmlword - **Description**: 基于html-docx-js ,一款 用于html页转word文档的工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4 - **Created**: 2024-11-05 - **Last Updated**: 2024-11-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 安装 ``` npm install xh-htmlword ``` ## 导入 ```js import handleExportWord from "xh-htmlword"; ``` ## 页面 dom 生成后调用 ```js //在需要分页的地方添加 即可分页 // dom:需要渲染的html父盒子标签 , 类型:string 例如 id/class // fileName:文件名称 类型:string // timeOut:设置导出图片加载 超时时间 默认值 5000 (5s) // callBack:导出成功回调函数 // options:配置项 类型:object 例如可传 {left:1440,right:1440} 控制页边距 // defultImg: 错误或者超时图片 默认图片地址 类型:string // className:当前组件的class属性名标识 类型:string 配置此项后可以在标签写入class样式 // drawCanvas:当当前页面有比较复杂的样式或组件(element-ui等) 页面中可以用样式标签将它包裹起来然后将标签 传入drawCanvas数组中 开启转换 handleExportWord({ dom: ".export-box", fileName: "cs", timeOut: 3000, callBack: (res) => { console.log("导出成功"); //res 文档流 }, defultImg: "", className: "export-box", drawCanvas: [".tree", "#btn"], }); ``` ## 示例 vue 模版 ```js 深水汴北配套管网运维日报表 {{ item2.title }} {{ item2.label }} 到岗人员: {{ item.title }} {{ item.label }} 标准化执行情况: {{ data.execution == index ? "√" : "□" }} {{ item }} 巡检记录 分页 分页 导出 ``` ## 使用须知 由于 html-docx-js 已经无人维护版本较老(直接使用坑非常多),现修改使用成 xuhao-htmlword 用于生成 word 文档,已解决老语法兼容问题, 添加部分 ts 声明 以及图片跨域文本处理等缺陷升级,交流联系:1031945252@qq.com ## 注意事项 html 模版需要全局使用行内样式,否则生成的 word 文档样式不生效,img 标签可以使用 width/height 属性设置宽高,建议全局使用 pt 作为尺寸单位 绝大部分 css3 样式无法生效,建议直接使用原生 table 标签编写 ## 开源协议 ISC
深水汴北配套管网运维日报表