vs2010,office2007,C#winform,在程序窗体中打开excel文件 [有关问题点数:100分]
vs2010,office2007,C#,winform,在程序窗体中打开excel文件 [问题点数:100分]
就是在vs2010编写的winform程序打开电脑上的的excel文件,试过网上的几种办法都没成功,求大神帮忙实现,使用第三方开源控件也行,介绍下具体方法。用webbrowser那种就算啦。求大神帮忙!
------解决方案--------------------
楼主的意思是 把excel嵌到 winform内
------解决方案--------------------
微软的OWC组件你试过吗?
------解决方案--------------------
是webservice
http://www.cnblogs.com/denylau/archive/2010/07/23/1783530.html
------解决方案--------------------
我之前做过一个,这是代码希望能帮到你。要引用空间using Microsoft.Office.Interop.Excel;
这是代码
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
ofd.Title = "打开Excel";
ofd.Filter = "Excel文件(*.xls;*.xlsx)
------解决方案--------------------
*.xls;*.xlsx";
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
ofd.RestoreDirectory = true;
string str = @"" + ofd.FileName;
if (!string.IsNullOrEmpty(str))
{
try
{
string strOdbcCon = "Provider=Microsoft.ACE.OleDb.12.0;" + "Data Source=" + str + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";//设置Excel文件位置
OleDbConnection OleDB = new OleDbConnection(strOdbcCon);
OleDbDataAdapter OleDat = new OleDbDataAdapter("select*from[sheet1$]", OleDB);
DataSet dt = new DataSet();
OleDat.Fill(dt);
this.dgv_motor.DataSource = dt.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); //弹出异常提示信息
}
}
else
{
MessageBox.Show("您要导入的文件错误!");
}
------解决方案--------------------
我这个Excel文件是在dataGridView控件中显示的,所以有这一句this.dgv_motor.DataSource = dt.Tables[0].DefaultView;
就是在vs2010编写的winform程序打开电脑上的的excel文件,试过网上的几种办法都没成功,求大神帮忙实现,使用第三方开源控件也行,介绍下具体方法。用webbrowser那种就算啦。求大神帮忙!
C#编程
打开excel文件
vs2010
winform程序显示
------解决方案--------------------
楼主的意思是 把excel嵌到 winform内
------解决方案--------------------
微软的OWC组件你试过吗?
------解决方案--------------------
是webservice
http://www.cnblogs.com/denylau/archive/2010/07/23/1783530.html
------解决方案--------------------
我之前做过一个,这是代码希望能帮到你。要引用空间using Microsoft.Office.Interop.Excel;
这是代码
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
ofd.Title = "打开Excel";
ofd.Filter = "Excel文件(*.xls;*.xlsx)
------解决方案--------------------
*.xls;*.xlsx";
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
ofd.RestoreDirectory = true;
string str = @"" + ofd.FileName;
if (!string.IsNullOrEmpty(str))
{
try
{
string strOdbcCon = "Provider=Microsoft.ACE.OleDb.12.0;" + "Data Source=" + str + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";//设置Excel文件位置
OleDbConnection OleDB = new OleDbConnection(strOdbcCon);
OleDbDataAdapter OleDat = new OleDbDataAdapter("select*from[sheet1$]", OleDB);
DataSet dt = new DataSet();
OleDat.Fill(dt);
this.dgv_motor.DataSource = dt.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); //弹出异常提示信息
}
}
else
{
MessageBox.Show("您要导入的文件错误!");
}
------解决方案--------------------
我这个Excel文件是在dataGridView控件中显示的,所以有这一句this.dgv_motor.DataSource = dt.Tables[0].DefaultView;