我有一个excel文件存在以下问题,我希望使用下一个代码在C#中将其各自单元格的值大写:
DbProviderFactory factory =
DbProviderFactories.GetFactory("System.Data.OleDb");
DbConnection connection = factory.CreateConnection();
string stringConnection = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=NO;IMEX=1'",
excelPath);
connection.ConnectionString = stringConnection;
connection.Open();
DbCommand updateExcel =
factory.CreateCommand();
updateExcel.CommandText =
"UPDATE [sheet1$] SET lastname = UCASE(lastname), name = ucase(name)";
updateExcel.Connection = connection;
updateExcel.ExecuteNonQuery();
conection.Close();
connection.Dispose();
它引发了关于参数未指定的oledbexception,任何人都可以帮助我吗?
答案 0 :(得分:0)
如果您尝试连接到Excel 2007或2010电子表格,则需要以下连接字符串...
OleDbConnection xlconnection = new OleDbConnection();
xlconnection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + @";Extended Properties='Excel 12.0;HDR=YES;IMEX=1'"