首页 > 其他分享 >html-docx-js 导出word

html-docx-js 导出word

时间:2024-04-29 17:33:06浏览次数:16  
标签:docx word 导出 html let nbsp font echarts

1:列表页面按钮

<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="exportWorddata"
>导出word</el-button>

 

<ExportWord ref="exportWord"/>

import ExportWord from './ExportWord.vue'

 components: { ExportWord },

exportWorddata(){
this.$refs.exportWord.initdata()
},

2:导出页面    点击 初始化echarts  点击 初始化echarts图片 点击  导出

<template >
<el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
<div slot="footer">
<el-button type="primary" @click="daochu">导出</el-button>
<el-button type="primary" @click="initdata">初始化echarts</el-button>
<el-button type="primary" @click="getImg">初始化echarts图片</el-button>
<el-button @click="cancel">关 闭</el-button>
</div>
<div id="htmlcontent">
<div id="demo">
<div class="toptitle">测试导出word</div>
<div class="title_sub">
<span>检查时间:2021年07月20日</span
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span>检查地点:巡检点1</span>
</div>
<table border="1" class="table_style">
<!-- 头 -->
<thead>
<th>序号</th>
<th>检查内容</th>
<th>检查情况</th>
<th>责令当场改正情况</th>
</thead>
<!-- body -->
<tbody>
<tr v-for="(item, i) in approvalLogs" :key="i">
<td>{{ i + 1 }}</td>
<td>{{ item.approveMsg }}</td>
<td>{{ item.approveDate }}</td>
</tr>
<tr style="height: 150px">
<td colspan="2">检查人员(签名)</td>
<td colspan="2">张三,李四,王五</td>
</tr>
<tr style="height: 100px">
<td colspan="2">单位领导(签名)</td>
<td colspan="2">张三</td>
</tr>
</tbody>
</table>
<img :src="imgSrc" width="590" height="360" />
<div style="height: 350px; width: 600px">
<div id="juZuChart1" style="height: 100%; width: 100%" />
</div>
</div>
</div>

</el-dialog>

</template>
<script>


// npm install file-saver
// npm install html-docx-js
import htmlDocx from "html-docx-js/dist/html-docx";
import FileSaver from "file-saver";
import * as echarts from 'echarts';

export default {

data() {
return {
title: "",
open: false, // 表单参数

myChart:null,
imgSrc:'',
approvalLogs:[
{
approveMsg:"测试数据1",
approveDate:"测试数据2"
}
],
};
},
mounted() {

},
methods: {
// 取消按钮
cancel() {
this.open = false;

},

initdata (){
let _this = this;
_this.open = true;
_this.title = "导出word";
this.initEchart()
},

daochu(){
let contentHtml = document.getElementById("htmlcontent").innerHTML;
let cssHTML = `#demo {
width: 800px;
margin: auto;
padding: 40px;
box-sizing: border-box;
}
#demo .toptitle {
width: 100%;
text-align: center;
font-size: 25px;
font-weight: bold;
}
#demo .title_sub {
padding: 30px 0;
}
.table_style td,
th {
padding: 10px;
font-size: 15px;
}
.table_style {
border-collapse: collapse;
width: 100%;
text-align: left;
}`;
let content = `
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
${cssHTML}
</style>
</head>
<body>
${contentHtml}
</body>
</html>`;
let converted = htmlDocx.asBlob(content);
FileSaver.saveAs(converted, "测试导出.docx");
},

//*************Echart数据************************
initEchart() {
// 基于准备好的dom,初始化echarts实例
this.myChart = echarts.init(document.getElementById('juZuChart1'));

// 指定图表的配置项和数据
let option = {
title: {
text: 'ECharts 折线图示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'line',
data: [5, 20, 36, 10, 10, 20]
}]
};

// 使用刚指定的配置项和数据显示图表。
this.myChart.setOption(option)

},
// 获取echarts图片
getImg() {
this.imgSrc = this.myChart.getDataURL({
type: 'png',
pixelRatio: 2,
backgroundColor: '#fff'
});
},
//*************Echart数据************************

},
computed: {

},
mounted() {

},

};
</script>
<style lang="scss" scoped>
.demo {
width: 800px;
margin: auto;
padding: 40px;
box-sizing: border-box;
}
.demo .toptitle {
width: 100%;
text-align: center;
font-size: 25px;
font-weight: bold;
}
.demo .title_sub {
padding: 30px 0;
}
.table_style td,
th {
padding: 10px;
font-size: 15px;
}
.table_style {
border-collapse: collapse;
width: 100%;
text-align: left;
}

</style>

 

 

标签:docx,word,导出,html,let,nbsp,font,echarts
From: https://www.cnblogs.com/xueershewang/p/18166340

相关文章

  • 实现HTML标签的转义、反转义的几种方法
    原文链接:https://blog.csdn.net/huanggang0101/article/details/99621029方法一:通过正则表达式进行替换1,HTML标签的转义方法//HTML标签转义(<-----><)functionhtml2Escape(sHtml){returnsHtml.replace(/[<>&"]/g,function(c){return{'<':�......
  • day27-HTML
    1.web开发1.1、最简单的web应用程序importsocketsock=socket.socket()sock.bind(("127.0.0.1",8800))sock.listen(5)while1:print("serverisworking...")conn,addr=sock.accept()recv_data=conn.recv(1024)conn.send(b"HTTP/1.......
  • WordPress操作文章类常用的动作钩子
    publish_post:参数一个($post_ID),点击发布文章时就会被触发;save_post:参数一个($post_ID),发布或更新文章时就会被触发;edit_post:参数两个($post_ID,$post),只要编辑已经存在的文章就会被触发;publish_future_post:参数一个($post_ID),到定时发布文章设定的时间点就会被触发,如果设定的时间早于......
  • 使用 WordPress搭建一个个人博客
    安装LNMP首先需要下载LNMP:wgethttp://soft.vpser.net/lnmp/lnmp2.0.tar.gz-cOlnmp2.0.tar.gz下载完成后解压并执行:tarzxflnmp2.0.tar.gz&&cdlnmp1.5&&./install.shlnmp选择想要安装的版本然后回车开始安装,这里时间比较长,耐心等待一下,看到以下显示表示安装成功配......
  • HTML转义字符
    原文链接:https://blog.csdn.net/fengxing11/article/details/39827753HTML中<,>,&等有特别含义,(前两个字符用于链接签,&用于转义),不能直接使用。使用这三个字符时,应使用他们的转义序列。转义字符串(EscapeSequence)也称字符实体(CharacterEntity)。在HTML中,定义转义字符串的原因......
  • HTML一键打包APK工具一机一码功能更新 - 增强安全性
    HTML一键打包APK工具在上一个版本更新的时候,添加了一机一码功能,该功能上线以来,受到许多用户的喜爱。它可以方便的让APK只能在已经授权的手机上使用,能有效地保护APK作品,防止一些没有授权的传播。如果想要向用户收费或者限制使用范围,这个功能就非常适合。之前版本中,在HTML一键打包A......
  • 在html中应用JavaScript
    1.在html中调用jsjs需要用<script>脚本写入位置</script>声明;也可以用外部文件引入,如<scripttype="text/javascript"src="script1.js"></script>。当js位于html的<head>内:这些脚本在选择触发它的时候被触发当js位于html的<body>内:这些脚本在页面加载时触发2.js的数据类......
  • threejs 浏览器窗口resize变化 自适应 html 全屏
    全屏:画布全屏和body页面全屏;//导入threejsimport*asTHREEfrom"three";import{OrbitControls}from"three/examples/jsm/controls/OrbitControls.js";//创建场景sceneconstscene=newTHREE.Scene();//console.log(scene,'scene');//......
  • swordswoman
    Ispentalmostmywholelifeinthecastlesilentlyasasimplewoman.Inthedailylife,Ipretendedtobeabeetandweakoldwoman.However,Ihopedtobecomeaswordswomaninthebottomofmyheart.Inthepast,noonebelievedthatawomancouldbeco......
  • Linux 配置 wkhtmltopdf
    官网地址wkhtmltopdf:https://wkhtmltopdf.org/作用:可以把html页面转换成pdf格式Linux下安装wkhtmltopdf检查linux服务器版本在官网根据版本下载安装#liunx下载版本:centos8wkhtmltox-0.12.6-1版本wgethttps://github.com/wkhtmltopdf/packaging/releases/download/......