XML转换_xml文件转化为excel格式
2023-06-13 09:11:01 时间
大家好,又见面了,我是你们的朋友全栈君
xml 文件
<?xml version="1.0" encoding="utf-8"?>
<ModelMetadata version="1">
<!--Spatial Reference System-->
<SRS>EPSG:4326</SRS>
<!--Origin in Spatial Reference System-->
<SRSOrigin>1222.02055172,31222.003238869999993,122292.25000000134497</SRSOrigin>
<Texture>
<ColorSource>Visible</ColorSource>
</Texture>
</ModelMetadata>
代码html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>xml 读取转换 excel</title>
<script src="../JS/comonJs/jquery-2.2.4.min.js"></script>
<style>
html,body{
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
#button{
width: 100px;
height: 80px;
border-radius: 5px;
position: absolute;
top: 1%;
left: 40%;
line-height: 80px;
border: 1px solid red;
font-size: 20px;
text-align: center;
}
#table{
width: 600px;
height: 450px;
border: 1px solid #212121;
position: absolute;
top: 12%;
border-collapse: collapse;
}
tr td{
border: 1px solid #212121;
width: 100px;
text-align: center;
}
</style>
</head>
<body>
<h1>xml 读取转换 excel</h1>
<div id="button" οnclick="loadXML()">点击转换</div>
<table id="table">
<tr>
<th>name</th>
<th>jd</th>
<th>wd</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
<script>
$(function () {
document.getElementById('table').rules="rows"
document.getElementById('table').rules="cols"
})
function loadXML() {
let xmlDoc,xmlhttp,x,name,jd,wd;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","../xmlfile/metadata.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x = xmlDoc.getElementsByTagName("ModelMetadata");
console.log(x[0].attributes)
let value =xmlDoc.getElementsByTagName("SRS")[0].childNodes[0].nodeValue;
console.log(value)
tableToExcel("table")
}
$("#table").append("<tr><td>"+name+"</td><td>"+jd+"</td><td>"+wd+"</td></tr>")
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,',
template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',
base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
format = function(s, c) {
return s.replace(/{(\w+)}/g,
function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
</body>
</html>
页面效果:
下载后:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/171935.html原文链接:https://javaforall.cn
相关文章
- 导出的Excel名字乱码_恢复的excel文件乱码
- JavaScript SheetJS将 Html 表转换为 Excel 文件
- mysql导入excel文件_将Excel数据导入MySQL「建议收藏」
- Python xlwt数据保存到 Excel中以及xlrd读取excel文件画图
- 学习LAMBDA函数:将Excel公式转换为自定义函数(上)
- 学习LAMBDA函数:将Excel公式转换为自定义函数(下)
- 使用POI生成Excel文件,可以自动调整excel列宽详解编程语言
- 操作excel展示Linux下Poi妙用:操作Excel(linux下poi)
- 数据库用Excel快速导入Oracle数据库(excel导入oracle)
- MySQL数据导出Excel快速教程(mysql转excel)
- MySQL导入Excel:一步步实现数据导入(mysql导入excel)
- 将Excel表格数据导入MySQL数据库(excel到mysql)
- 从Excel快速导入Oracle数据库(excel到oracle)
- C#实现EXCEL数据到TXT文档的转换
- asp.net导出excel的简单方法实例