vue3+mammoth.js 实现word导入转html
vue3+mammoth.js 实现word导入转html
·
1,npm install mammoth
2,在页面中使用
<template>
<input type="file" id="fileInput" />
</template>
<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref, shallowRef } from 'vue'
import mammoth from 'mammoth'
onMounted(() => {
document.getElementById('fileInput').addEventListener('change', function (e) {
const file = e.target.files[0];
console.log(file)
if (file.name.indexOf('.docx') < 0) return alert('只支持上传docx后缀的表格!')
console.log(file)
const reader = new FileReader();
reader.readAsArrayBuffer(file)
reader.onload = (event) => {
mammoth.convertToHtml({ arrayBuffer: event.target.result })
.then(result => {
console.log(result.value)
});
};
})
});
</script>
备注:解出来的html没有内联样式,只能解出来内容
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)