使用Javascript/classic-ASP将XML导出到Excel电子表格 [英] Export XML to Excel spreadsheet using Javascript/classic-ASP

查看:90
本文介绍了使用Javascript/classic-ASP将XML导出到Excel电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript将XML数据从网页导出到电子表格.到目前为止,我已经尝试了非常简单的方法:

I'm trying to export XML data from a web page to a spreadsheet using javascript. So far I've just tried the very simple:

Sub Export
    Response.ContentType = "application/vnd.ms-excel"
    <script>            
         var XML = document.getElementById("xmldata");              
         window.open(XML);
    </script>
End Sub

这会尝试将XML文件作为excel电子表格打开,但是由于包含无效字符而无法打开.我已经找到了这些字符,而罪魁祸首往往是水平横线"–".可能还有其他无效字符,但是如果我手动将其删除,则XML文件可以很好地打开.

This tries to open the XML file as an excel spreadsheet, however it doesn't open because it has invalid characters. I've tracked down these characters and the main culprit tends to be the horizontal dash "–". There may be other invalid characters, but If I remove them manually, the XML file opens fine.

我该如何格式化XML内容以删除或替换无效字符以正确显示为excel? XML工作表是根据数据库中的字段构建的,我应该在构建时对其进行格式化还是使用javascript对其进行格式化?我正在尝试找到最简单的解决方案,因为我是Web编程的新手.另外,我正在使用经典的ASP/VBscript.

How would I go about formatting the XML content to remove or replace the invalid characters to display properly to excel? The XML sheet is built from fields in a database, should I format it as it's built or format it with javascript? I'm trying to find the simplest solution possible as I'm fairly new to web programming. Also, I'm using classic ASP/VBscript.

推荐答案

通过从XML数据获取HTML表输出,然后使用ActiveX将其输入到Excel中来解决该问题.

Managed to solve it by getting the HTML table output from the XML data then putting that into Excel using ActiveX.

var x=listingTable.rows

var xls = new ActiveXObject("Excel.Application")
xls.visible = true
xls.Workbooks.Add

for (i = 0; i < x.length; i++)
{
    var y = x[i].cells

    for (j = 0; j < y.length; j++)
    {
        xls.Cells( i+1, j+1).Value = y[j].innerTex
    }
}

这篇关于使用Javascript/classic-ASP将XML导出到Excel电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆