XML转换_xml文件转化为excel格式

XML转换_xml文件转化为excel格式xml文件<?xmlversion=”1.0″encoding=”utf-8″?><ModelMetadataversion=”1″><!–SpatialReferenceSystem–><SRS>EPSG:4326</SRS><!–OrigininSpatialReferenceSystem–><SRSOrigin>1222.02055172,31.

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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>

页面效果:

XML转换_xml文件转化为excel格式

 下载后:

XML转换_xml文件转化为excel格式

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/171935.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号