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格式

 

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • ClientScriptManager.RegisterStartupScript.

    ClientScriptManager.RegisterStartupScript.当我们要注册一个在页面启动的脚本时,我们会用ClientScriptManager.RegisterStartupScript。比如<%@PageLanguage=”C#”%><!DOCTYPEhtmlPUBLIC”-//W3C//DTDXHTML1.0Transitional//EN””http://www.w3.org/TR/xhtml1/D…

    2022年7月20日
    16
  • executescalar mysql_ExecuteScalar

    executescalar mysql_ExecuteScalar这两个答案和一点点思考使我想到了一个接近答案的东西。首先再澄清一下:该应用程序是用C#(2.0+)编写的,并使用ADO.NET与SQLServer2005进行通信。镜像设置是托管主体和镜像的两个W2k3服务器以及托管作为监视器的快速实例的第三个服务器。这样做的好处是,故障转移对于使用数据库的应用程序几乎是透明的,它将对某些连接引发错误,但从根本上讲一切都会很好地进行。是的,我们得到了奇怪的误报…

    2022年6月30日
    27
  • ListView 使用方法(Asp.Net)

    ListView 使用方法(Asp.Net)

    2021年12月7日
    40
  • html注释快捷键

    html注释快捷键1.选中需要注释的内容—>ctrl+shift+/2.取消注释—>ctrl+shift+\转载于:https://www.cnblogs.com/wyhluckdog/p/10131898.html

    2022年4月27日
    116
  • QcustomPlot 多条单条曲线光标自动更随的实现

    QcustomPlot 多条单条曲线光标自动更随的实现QcustomPlot光标跟随最近有一个需求是能绘制多条曲线且能光标跟随,上网搜了很多相关的资料,如下边这个博客中查到了鼠标更随的相关代码,他的图如下所示——[原文链接地址](https://blog.csdn.net/sunnyloves/article/details/82344815)还有一篇如下所示——[原文链接地址](https://www.cnblogs.com…

    2022年10月16日
    3
  • C++结构体和类的区别_c++有结构体吗

    C++结构体和类的区别_c++有结构体吗这是对多个博客的总结————————————————————————————区别:1.结构体是一种值类型,而类是引用类型。值类型用于存储数据的值,引用类型用于存储对实际数据的引用。那么结构体就是当成值来使用的,类则通过引用来对实际数据操作。2.结构使用栈存储(Stac…

    2025年6月19日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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