word转换html插件,撸个插件给你word-to-html

1460000019821354?w=5000&h=2952

最近遇到一个需求,需要将非常多内容的(文字/表格)word文档展示出来,这个需求出现在pc端就用插件好了或者直接下载文件?如果需求是在移动端呢?怎么办?转成html吧。。。几十页的word怎么搞?为了造福大家,花了几天时间撸了一个插件word-to-html,可以转嵌套的表格,合并单元格的表格,github地址.

1460000019821355?w=327&h=504

emmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm!

安利一波其他项目:

时间仓促,代码写得有点乱,这里贴一下reamde吧,谁用谁知道哈,如果解决给位的痛点,希望不要吝啬您的star,非常欢迎提issue,大家一起讨论完善。由于用到了jsdom,这个库模拟出来的DOMpaser有点弱,如果你选择在浏览器中用我的给的方法,你甚至能将word中每一行不同文字的字体字号都转成对应的html,借助浏览器的js调试面板的源码我放在了github上对应项目的test/browser文件夹中了。

下面是readme:

word-to-html

14600000198213561460000019821357

A tiny tool to convert Microsoft Word document to HTML in Nodejs and in chrome,

you can use the tool convert tables with merged cells and nested tables to html file in Nodejs or chrome, the online tool wordhtml can not do this.

Beyond that, you can convert words with different font-family or font-size in a line to html string in chrome.

table example

attention

If a line of words have different font-family or font-size in your .docx, it can not convert

your .docx to html expectly in nodejs, but this can fix in the browsers such as chrome. because

the npm package jsdom can not realize the DOMParser's function perfectly.

So if you want to convert the font-family and font-size exactly, you can see how to use word2html.js in browsers!

Install

npm i word-to-html --save-dev

or

yarn add word-to-html

api in nodejs: word2html(absPath [,options])

absPath: string | Array

absPath is your file's absolute path

options: {tdTextAlign:string,tdVerticalAlign:string}

tdTextAlign controls the

tag's text-align

tdVerticalAlign controls the

tag's vertical-align

Usage in nodejs

var path = require('path');

var word2html = require('word-to-html');

//Word document's absolute path

var absPath = path.join(__dirname,'test.docx');

word2html(absPath,{tdVerticalAlign:'top'})

the html generated in your WorkSpace.

Usage in browsers

details in my github

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值