web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

纯js根据table页面样式导出excel表格(包括居中,合并,自定义样式)

1117 ℃

功能介绍:需要做一个xls导出功能,可以把页面上的自定义样式(居中、合并、背景颜色、字体大小、加粗等)一起导入到excel表格中!

自定义一个table表格

<table border="1" cellpadding="15">
  <tr>
    <th height="35" colspan="6" style="font-size:20px; background:red">辞职信</th>
  </tr>
  <tr>
    <td height="35" >姓名</td>
    <td height="35" width="200">张三</td>
    <td height="35">部门</div></td>
    <td height="35" width="200">技术部</td>
    <td height="35">职务</td>
    <td height="35" width="200">大佬</td>
  </tr>
  <tr>
    <td height="35">理由</td>
    <td height="35" colspan="5">世界这么大,我想去看看!</td>
  </tr>
  <tr>
    <td height="35" colspan="5" align="right">领导签名</td>
    <td height="35">&nbsp;</td>
  </tr>
</table>

excel表格导出代码

var tableHTML = document.querySelector("table").outerHTML;
var xlsContent= `<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns="http://www.w3.org/TR/REC-html40">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="ProgId" content="Excel.Sheet" /> 
</head>
<body>${tableHTML}</body>
</html>`; 
var blob = new Blob([xlsContent], { type: "application/vnd.ms-excel" });
var link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "下载.xls";
link.innerHTML = "下载xls"
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

Excel小技巧:如何快速分析Excel表格中的数据(图表步骤介绍)

简单介绍Excel表格中的6个求和函数

利用Excel表格做图表,附4个示例(Excel图表制作应用)

excel表格如何重复项筛选标色

excel表格如何在不改变网格的情况下进行换行?

标签: excel表格, xls导出, 导出功能

上面是“纯js根据table页面样式导出excel表格(包括居中,合并,自定义样式)”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2667.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计1209个字,预计阅读时长9分钟
Trae:新一代免费的AI编程工具

基金从业资格考试题库

一站式备考基金从业资格考试,收录2021-2025年模拟题库!呱呱工具箱

AI工作站

收录全球3800+ 款各行各业AI应用,轻轻松松做事!
生活小工具,收录了80多款小工具
上一篇: win7系统设置防火墙报0x8007042c错误解决方法
下一篇: 国家送给全国人民的9个免费神器(赶紧收藏)
x 打工人ai神器