写作与OLEDB Excel文件 [英] Writing into excel file with OLEDB
本文介绍了写作与OLEDB Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何通过OLEDB写入到一个Excel文件(.xls)在C#中?我做的是以下内容:
Does anyone know how to write to an excel file (.xls) via OLEDB in C#? I'm doing the following:
OleDbCommand dbCmd = new OleDbCommand("CREATE TABLE [test$] (...)", connection);
dbCmd.CommandTimeout = mTimeout;
results = dbCmd.ExecuteNonQuery();
但我得到的消息抛出OleDbException:
But I get an OleDbException thrown with message:
无法修改表的设计
'测试$'。它是在一个只读
数据库。
"Cannot modify the design of table 'test$'. It is in a read-only database."
我的连接看起来不错,我可以选择的数据不错,但我似乎无法将数据插入到Excel文件,没有人知道我是怎么读到Excel /写访问通过OLEDB文件?
My connection seems fine and I can select data fine but I can't seem to insert data into the excel file, does anyone know how I get read/write access to the excel file via OLEDB?
推荐答案
您需要添加只读= FALSE;
来连接字符串
You need to add ReadOnly=False;
to your connection string
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=fifa_ng_db.xls;Mode=ReadWrite;ReadOnly=false;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";
这篇关于写作与OLEDB Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文