纯前端table和echarts图片导出excel表格

 

 

<table class="common_table" id="tabDiv1">
    <thead>  
        <tr>
		    <th rowspan="2">流域</th>
		    <th rowspan="2">责任市州</th>
		    <th rowspan="2">断面名称</th>
		    <th rowspan="2">所在水体</th>
		    <th rowspan="2">{{yearStr}}年考核目标</th>
		    <th rowspan="2">月份</th>
		    <th colspan="2">水质变化情况</th>
		    <th colspan="6">差异管控类别</th>
		    <th rowspan="2">趋势研判</th>
		    <th rowspan="2">目标预警</th>
	    </tr>
        <tr>
		    <th>水质类别(本年/上年同期)</th>
			<th>指数CWQI(本年/上年同期)</th>
			<th>超标因子(对比考核目标)</th>
			<th>超出因子(对比Ⅲ类)</th>
			<th>超出因子(对比Ⅱ类)</th>
			<th>定类因子</th>
			<th>超出频次(对比Ⅲ类)</th>
			<th>超出频次(对比Ⅱ类)</th>

		</tr>
        
    </thead>
    <tbody>
        <tr>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td>
            <td>1111</td> 
            <td>1111</td>
            <td>1111</td> 
        </tr>

    </tbody>
</table>
<div class="item-echarts hydrologyForecast" id="Line" ref="Line"></div>
//js部分

base64(content) {
	return window.btoa(unescape(encodeURIComponent(content)));
},


tableToExcel() {
            //这里把echart转化成图片,也可以把这个放在生成echart的位置,但是我这边测试生成的图                        //片没有数据
            this.imagesBase64=this.myChart.getDataURL('png');
			this.$message({
		          message: '正在导出...',
		          type: 'success',
		           offset:'150'
		     });

           // 这里是要导出的table的id
			var excelContent = $("#tabDiv1").html();
            //这里把图片添加在img标签
            var images='<img src="'+this.imagesBase64+'"/>';
			var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
			excelFile += "<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head>";
			excelFile += "<body><table width='10%' border='1'>";
			excelFile += excelContent;
			excelFile += "</table>"
			excelFile += images;
			excelFile += "</body>";
			excelFile += "</html>";
			var link = "data:application/vnd.ms-excel;base64," +                         this.base64(excelFile);
			var a = document.createElement("a");
            //这里是要导出的文件名字
			a.download = "断面文件" + ".xlsx";
			a.href = link;
			a.click();
},
//echart部分
		EchartLine(dataX,seriesData1,seriesData2){
				this.myChart = echarts.init(this.$refs.Line); //图标初始化
				var option = {
                        color:['#7030A0','#ED7D31'],
                         title: {
					      left: 'center',
					      text: '重点流域水功能区达标情况',
					      top:10,
					      textStyle:{
					      	fontSize:16
					      }
					    },
                        tooltip: {
                            trigger: 'axis',
                            
                        },
						legend: {
                        	bottom:"0px",
                            left: 'center',
							data:['达标谁功能区个数','水功能区达标率']
                        },
                        grid: {
                            top:"20%",
                            left: '5%',
                            right: '5%',
                            bottom: '10%',
                            containLabel: true
                        },
                        xAxis: {
                           /// boundaryGap: false,
                            type: 'category',
                            data:dataX,
                            axisLabel:{  
                                interval:0,
                                rotate:70,
                            },
                            
                        },
                        yAxis: [
							{
								type: 'value',
								axisLine: {
									lineStyle: {
										color: '#7030A0'
									}
								},
							},
							{
								type: 'value',
								position: 'right',
								axisLine: {
									lineStyle: {
										color: '#ED7D31'
									}
								},
								axisLabel: {
									formatter: '{value} %'
								}
							},

						],
                        series: [
							{
								name:'达标谁功能区个数',
								type:'bar',
								"barMaxWidth":"30%",
								data:seriesData1
							},
							{
								name:'水功能区达标率',
								type:'line',
								yAxisIndex: 1,
								data:seriesData2
							}
						]
                    };
					this.myChart.setOption(option,true);
					

			}





  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值