具有更新Excel单元的OLEDB [英] OLEDB with updating excel cells
本文介绍了具有更新Excel单元的OLEDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了此方法来更新Excel单元格:
I wrote this method to update an excel cell:
public void update(string fileName, string sheetName)
{
string connString = connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(fileName) + ";Extended Properties=Excel 12.0";
try
{
OleDbConnection oledbConn = new OleDbConnection(connString);
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("UPDATE ["+sheetName+"$B5:B5] SET F1=17", oledbConn);
cmd.ExecuteNonQuery();
oledbConn.Close();
}
catch(Exception ex)
{
Debug.Write("Error: " + ex.Message);
}
}
我这样称呼它:
update("test.xls", "test");
测试"表中提供了B5单元格,但该值从未更新.
The B5 cell is available in "test" sheet, but the value never gets updated.
我什至尝试了这个:
UPDATE ["+sheetName+"$B5:B5] SET F1='17'
而且我总是遇到这样的例外:没有为一个或多个必需参数提供任何值.
and I always got this exception: No value given for one or more required parameters.
有什么主意吗?
先谢谢了.
推荐答案
EDIT我注意到您错过了HDR = No.
EDIT I notice you have missed HDR=No.
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName +
";Extended Properties=""Excel 12.0;HDR=No"""
编辑 在C#Express中测试
EDIT Tested in C# Express
要么:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=z:\\docs\\myspreadsheet.xls;Extended Properties='Excel 12.0 xml;HDR=No'"
注意xml
或
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=z:\\docs\\myspreadsheet.xls;Extended Properties='Excel 8.0;HDR=No'"
对于* .xls
这篇关于具有更新Excel单元的OLEDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文