使用oledb类打开.xls文件的问题 [英] Problem with open .xls file using oledb class
本文介绍了使用oledb类打开.xls文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家!
我想用.xls格式打开excel文件。然后我得到一个错误''外部表不是预期的格式。''如何解决这个错误。
这是我的连接字符串。
Provider = Microsoft.Jet.OLEDB.4.0;数据源= D:\official \Sharad SVN \ SVN Projects'\\trunk \\ \\ ITMRepo \Exam \ExamPortal / ExcelFiles / Courses.xls;扩展属性=Excel 8.0; HDR =是; IMEX = 0
这是我打开文件的c#代码
使用 ( var conn = new OleDbConnection(connectionString))
{
conn.Open (); // 这里我收到错误:外部表格不是预期的格式。
var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object [] { null , null , null , TABLE});
使用( var cmd = conn.CreateCommand())
{
cmd.CommandText = SELECT * FROM [ + sheets.Rows [ 0 ] [ TABLE_NAME]。ToString()+ < span class =code-string> ];
var adapter = new OleDbDataAdapter(cmd);
var ds = new DataSet();
adapter.Fill(ds);
}
}
请帮助。高级中的thanx ....
解决方案
听起来你正试图连接excel文件版本2007-2010。
更改连接字符串,如下所示: http:// stackoverflow .com / questions / 1139390 / excel-external-table-is-not-the-the-expected-format [ ^ ]
外部表格不符合预期格式。
通常在我们使用带有以下连接字符串的Excel 2007文件时发生:Microsoft.Jet.OLEDB.4.0和扩展属性= Excel 8.0
使用以下连接字符串
string connStr = Provider = Microsoft.ACE.OLEDB.12.0; Data Source = + path + ;扩展属性= Excel 12.0;;
问候,
Babu.K
可能你应该尝试这样的东西......工作正常.. !!!
仅适用于.xls文件,path是存储文件的路径..
connString = Provider = Microsoft.Jet.OLEDB.4.0; Data Source = + path + < span class =code-string> ;扩展属性= \Excel 8.0; HDR = YES; IMEX = 1; Jet OLEDB密码= 1 \ 跨度>;
Hi Experts!
i want to open excel file with .xls format. then i got an error ''External table is not in the expected format.'' how to solve this error.
this is my connection string.
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\official\Sharad SVN\SVN Projects\trunk\ITMRepo\Exam\ExamPortal/ExcelFiles/Courses.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=0"
this is my c# code for open file
using (var conn = new OleDbConnection(connectionString))
{
conn.Open(); // here i got error: "External table is not in the expected format."
var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "] ";
var adapter = new OleDbDataAdapter(cmd);
var ds = new DataSet();
adapter.Fill(ds);
}
}
please help. thanx in advanced....
解决方案
It sounds like you''re trying to connect to excel file version 2007-2010.
Change connection string, as is shown here: http://stackoverflow.com/questions/1139390/excel-external-table-is-not-in-the-expected-format[^]
Hi,
"External table is not in the expected format."
Typically occurs when we are using an Excel 2007 file with a connection string that uses:Microsoft.Jet.OLEDB.4.0 and Extended Properties=Excel 8.0
Use the following connection string
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
Regards,
Babu.K
May be you should try something like this..it is working fine..!!!
It is for ".xls" file only and path is the path where your file gets stored..
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;Jet OLEDB Password=1 \"";
这篇关于使用oledb类打开.xls文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文