【发布时间】:2020-08-29 01:18:16
【问题描述】:
// 使用提供程序 Microsoft.ACE.OLEDB.12.0 上传时出错
System.InvalidOperationException: 'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册。'
// 使用提供程序 Microsoft.JET.OLEDB.4.0 上传时出错
System.Data.OleDb.OleDbException: '找不到可安装的 ISAM
请帮忙
// for browsing file
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Select File";
fdlg.FileName = txtFileName.Text;
fdlg.Filter = "Excel Sheet (*.xls)|*.xls|All Files(*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = fdlg.FileName;
}
}
// for importing excel file into datagridview
private void btnImport_Click(object sender, EventArgs e)
{
OleDbConnection theConnection = new OleDbConnection(@"provider=Microsoft.ACE.OLEDB.12.0;data source='" + txtFileName.Text+"';Extended Properties=\"Excel 15.0;HDR=YES;\"");
theConnection.Open();
OleDbDataAdapter theDataADapter = new OleDbDataAdapter("SELECT * FROM[Sheet1$]",theConnection);
DataSet theSD = new DataSet();
DataTable dt = new DataTable();
theDataADapter.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;## Heading ##
}
【问题讨论】:
-
您还没有指明您正在使用哪个前端堆栈,WinForms
DataGridView和大多数第三方数据网格产品提供了足够的功能,您无需借助导入功能来管理长列表数据,您是否考虑过为此构建数据网格条目 UI? -
这个问题不会吸引很多选票,因为它没有显示任何研究成果你应该包括一些你尝试过的思考过程或代码,即使它失败了,甚至是 excel 文件的结构,你就会吸引到更多有用的回复
标签: c# excel desktop-application