在datagridview中显示excel文件,并带有更改工作表的选项 [英] Display excel file in datagridview with option to change sheets
本文介绍了在datagridview中显示excel文件,并带有更改工作表的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个使用树视图选择文件的应用。我希望能够在winform上预览任何xls或xlsx。
我尝试了一些代码,但我总是收到错误:找不到可安装的isam,我不知道如何修复它。
有人可以帮帮我吗?
谢谢。
我有什么试过:
I currently have an app that uses a treeview to select files. I want to be able to preview any xls or xlsx on the winform.
I tried some code, but I always get an error: "could not find installable isam", and I don't know how to fix it.
Can someone please help me?
Thanks.
What I have tried:
dataGridView1.BringToFront();
string temp = Path.GetDirectoryName(CurrentNode.FullPath);
temp = temp.Substring(0, temp.IndexOf("\\")) + "\\";
exactpath = Path.GetFullPath(Path.GetDirectoryName(CurrentNode.FullPath).Replace(temp, ""))+"\\"+Path.GetFileName(CurrentNode.FullPath);
MessageBox.Show(exactpath);
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + exactpath + ";Extended Properties=Excel 11.0;");
MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);
MyCommand.TableMappings.Add("Table", "Net-informations.com");
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet); //Error in this line
dataGridView1.DataSource = DtSet.Tables[0];
MyConnection.Close();
推荐答案
,MyConnection);
MyCommand.TableMappings .Add( 表, Net-informations.com);
DtSet = new System.Data.DataSet() ;
MyCommand.Fill(DtSet); // 此行中的错误
dataGridView1.DataSource = DtSet.Tables [ 0 ];
MyConnection.Close();
", MyConnection); MyCommand.TableMappings.Add("Table", "Net-informations.com"); DtSet = new System.Data.DataSet(); MyCommand.Fill(DtSet); //Error in this line dataGridView1.DataSource = DtSet.Tables[0]; MyConnection.Close();
导入使用C#和VB.Net从Excel文件到Windows窗体DataGridView的数据 [ ^ ]
这篇关于在datagridview中显示excel文件,并带有更改工作表的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文