.xlsx文件到.xml文件C# [英] .xlsx file to .xml file c#

查看:97
本文介绍了.xlsx文件到.xml文件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中将.xlsx文件转换为.xml文件,Excel文件具有成千上万条记录.任何建议都值得赞赏.

How to Convert .xlsx file to .xml file in c#, The Excel file has thousands of records.Any suggestion is appreciated.

推荐答案

猜猜,解决方案就像你写的问题一样小...


Guess, the solution is as small as you wrote your question ...


// Connect to Excel files
    System.Data.OleDb.OleDbConnection MyConnection ;
    System.Data.DataSet ds ;
    System.Data.OleDb.OleDbDataAdapter MyCommand ;
    MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='D:\\18.xls';Extended Properties=Excel 8.0;");
   MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1


",MyConnection中选择*; MyCommand.TableMappings.Add(" " 产品"); ds = System.Data.DataSet(); MyCommand.Fill(ds); MyConnection.Close(); // 写入xml ds.WriteXml(" );
", MyConnection); MyCommand.TableMappings.Add("Table", "Product"); ds = new System.Data.DataSet(); MyCommand.Fill(ds); MyConnection.Close(); // Write to xml ds.WriteXml("Product.xml");



将其标记为答案可以解决您的查询.



Mark it as answer it this solves your query.


由于xlsx文件是一个zip文件,其中包含workbook.xml文件和worksheets文件夹(以及其他文件).只需从文件夹中提取适当的工作表文件,然后查看它是否直接满足您的需求.如果没有,则可以使用XSL(T)(xml转换)来获取所需的内容.乍一看,如果您不熟悉它,进行此转换可能会有些复杂.但是通过这种方式,您可以获得可观的性能,并且您不需要Excel就能做到.
当然,您也可以找到一些不需要Excel的OpenXML解析器.
As the xlsx file is a zip with a workbook.xml file and a worksheets folder inside (among other files). Just extract the proper worksheet file from the folder, it and see if fits your needs directly. If not, you can use an XSL(T) (xml transform) to get what you need. Making this transform might seem a little bit complicated at first sight, if you are not familiar with it. But this way you gain considerable performance, and you don''t need Excel to do it.
Of course, you could find several OpenXML parsers also that don''t need Excel either.


这篇关于.xlsx文件到.xml文件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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