【问题标题】:How to append values to an Excel file?如何将值附加到 Excel 文件?
【发布时间】:2013-01-24 04:02:55
【问题描述】:

我知道这个问题很老了,但我找不到任何答案。

如何将值附加到现有的 Excel 文件和特定列中。

System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;

MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=filelocation;Extended Properties=Excel 8.0;");

MyConnection.Open();
myCommand.Connection = MyConnection;

sql = "Insert into ["+ sheetname +"$] (Result) values ("+ result +")";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();

我什至尝试了不同的方法,例如通过 C# 打开 Excel 并追加,但没有任何效果。

【问题讨论】:

    标签: c# excel append


    【解决方案1】:

    使用 OLEDB 处理 excel 文件有它的问题和缺点。最好使用第三方库。我推荐 CSharpJExcel 用于 Excel 97-2003 (xls) 文件或 EPPlus 用于 Excel 2007 (xlsx) 文件。您甚至不需要安装 Microsoft Excel。

    【讨论】:

      【解决方案2】:
      【解决方案3】:

      如果你不用OLEDBhere是一篇不错的文章如何使用早期绑定操作excel文件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-11
        • 1970-01-01
        • 1970-01-01
        • 2016-06-07
        • 1970-01-01
        相关资源
        最近更新 更多