none
如何把excel中的内容都提取出来存为txt文件? RRS feed

答案

  • 你好,

    这个问题的核心其实是如何从excel中读取数据然后格式化这些数据。

    OLEDB 可以用来读取excel,大致代码如下:

    string con =
      @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\test.xls;" + 
      @"Extended Properties='Excel 8.0;HDR=Yes;'";    
    using(OleDbConnection connection = new OleDbConnection(con))
    {
        connection.Open();
        OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection); 
        using(OleDbDataReader dr = command.ExecuteReader())
        {
             while(dr.Read())
             {
                 var row1Col0 = dr[0];
                 Console.WriteLine(row1Col0);
             }
        }
    }

    open xml sdk也可以用来读取excel,如果感兴趣可以 https://www.microsoft.com/en-us/download/details.aspx?id=30425

    从excel中读到内容之后就可以用foreach或者for循环来格式化得到的数据,最后保存到txt


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年9月28日 2:28