你怎么能编程XML数据导入到Excel文件? [英] How can you programmatically import XML data into an Excel file?

查看:173
本文介绍了你怎么能编程XML数据导入到Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面code应该帮我从Excel导出XML数据:

The following code should help me export XML data from Excel:

 Excel.Application application = new Excel.Application();
            application.Workbooks.Open(excelFilepath,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value,
                                    Missing.Value);

        string data = null;
        application.ActiveWorkbook.XmlMaps[1].XmlExport(out data);

现在我正在寻找code,这将有助于我的导入的XML数据到Excel中,就像我会通过手动点击开发选项卡上导入的文件,然后选择导入XML

Now I'm looking for code that will help me Import XML data into Excel, just as I would import a file manually by clicking on the "Developer" tab and then "Import XML".

谁能告诉我该怎么办呢?

Can someone tell me how to do it?

推荐答案

使用相同的系统,并在MSDN网站上。我花了很短的时间找到以下链接:

Using the same system, and the MSDN website. It took me a very short time to find the following Link:

<一个href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xmlmap.import%28v=office.14%29" rel="nofollow">http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xmlmap.import%28v=office.14%29

Excel的互操作中涉及到XmlMap的方法。那具体的环节是在XmlMap.Import功能,这需要一个url(文件路径)和进口的XML数据。

The Methods related to XmlMap within the Excel Interop. That specific link is to the XmlMap.Import function, which takes a url (filePath) and imports xml data.

另外还有一点,页面上的链接 ImportXml()的功能,它可以接受的XML字符串作为直接输入的功能,而不是使用的URL。

There is also on that page a link to the ImportXml() function, which can accept xml strings as direct input to the function rather than using a URL.

的code假定,对于这两种,即XmlMap已定义。我本人不知道如何以编程方式通过接口定义了一个Excel文档的XmlMap。

The code assumes, for both of these, that the XmlMap is already defined. I myself am not aware of how to programmatically define an XmlMap in an Excel Document via the interface.

这篇关于你怎么能编程XML数据导入到Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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