问题描述
请注意,这是Windows应用程序.
我上传了excel文件.当我读取excel文件时,其显示错误如下
microsoft.ace.oledb.12.0提供程序未在本地计算机上注册"
我使用以下代码读取excel文件,如下所示
Note it is windows application.
I upload excel file.when i read excel file, its show error as follows
the ''microsoft.ace.oledb.12.0'' provider is not registered on the local machine"
i uses following code read excel file as follows
Private void import()
{
String Pathname = txtFileName.Text;
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEB.12.0;Data Source = '" + Pathname + "'" + @";Extender Properties=""Excel 8.0;HDR=YES;IMEX=1;ImportMIxedTypes=Text;TypeGuessRows=0""";
conn.Open();
GSheetName = "";
DataTable dt = conn.GetSchema("Tables");
string sheetname = "";
foreach (DataRow row in dt.Rows)
{
sheetname = (string)row["TABLE_NAME"];
if (sheetname.EndsWith("$"))
{
GSheetName = sheetname.ToString().Trim();
break;
}
}
LblSheetName.Text = "Sheet Name :" + GSheetName.ToString().Trim();
if (GSheetName == "" || GSheetName == null)
{
progressBar1.Visible = false;
MessageBox.Show("Invalid Sheet Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
OleDbCommand command = new OleDbCommand("SELECT * From[" + GSheetName + "]", conn);
DataSet ds = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
progressBar1.Visible = false;
}
}
当我上传如下的excel文件错误时;
"microsoft.ace.oledb.12.0"提供程序未在本地计算机上注册."
请帮帮我.
问候,
Narasiman P
when i upload a excel file error as follows;
the ''microsoft.ace.oledb.12.0'' provider is not registered on the local machine".
please help me.
Regards,
Narasiman P
推荐答案
当我上传如下的excel文件错误时;
"microsoft.ace.oledb.12.0"提供程序未在本地计算机上注册."
请帮帮我.
问候,
Narasiman P
when i upload a excel file error as follows;
the ''microsoft.ace.oledb.12.0'' provider is not registered on the local machine".
please help me.
Regards,
Narasiman P
String ProviderExcel = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=";
String ExtendedPropertiesExcel = "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
String connString = ProviderExcel + filePath + ";" + ExtendedPropertiesExcel;
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(connString);
try
{
cn.Open();
DataTable schemaTable = cn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
string SheetName = schemaTable.Rows[0][2].ToString();
StringBuilder SelectStatement = new StringBuilder();
SelectStatement.Append("SELECT * FROM [").Append(SheetName).Append("]");
System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(SelectStatement.ToString(), cn);
DataTable objDataTable = new DataTable();
da.Fill(objDataTable);
}
尝试此代码.肯定会起作用..
谢谢
沙尔玛王子
[edit]已添加代码块,更正了行格式[/edit]
Try This code. Definatly it will work..
Thanks
Prince Sharma
[edit]Code block added, line format corrected[/edit]
这篇关于上载excel文件.当我读取excel文件时,其显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!