如何在 C# 中创建 xml 文件以与作为数据表导入的 .iqy 一起使用

chr*_*tle 5 c# xml excel

我想制作一个 Excel 文件,其中的数据会在我的网站上自动收集和更新,并显示为数据表。

我尝试从我创建的表中从网站导入,但它没有格式化为数据表。

我还创建了一个 xml 文件并使用 .iqy 文件来获取数据,但它仍然没有作为数据表导入

这是我的 .iqy 文件,它将导入数据,但不是作为 xml

WEB
1
http://localhost:55369/files/SerializationOverview.xml
Run Code Online (Sandbox Code Playgroud)

这是我的测试 xml 文件

  <?xml version="1.0"?>
    <bookstore>
      <book category="COOKING">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>30.00</price>
      </book>
      <book category="CHILDREN">
        <title lang="en">Harry Potter</title>
        <author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
      </book>
      <book category="WEB">
        <title lang="en">Learning XML</title>
        <author>Erik T. Ray</author>
        <year>2003</year>
        <price>39.95</price>
      </book>
    </bookstore>
Run Code Online (Sandbox Code Playgroud)

预先感谢您的帮助,非常感谢。

Leo*_*cia 0

读取 .iqy 文件的第三行/最后一行:

var url = File.ReadLines(@"query.iqy").Take(3).Last();
Run Code Online (Sandbox Code Playgroud)

然后下载 xml,如下所示:

using (var wc = new System.Net.WebClient())
{
   contents = wc.DownloadString(url);
}
Run Code Online (Sandbox Code Playgroud)

然后使用 解析 xml XDocument.Parse(contents),遍历 xml 并将数据写入数据库。