将Excel文件转换为C#Windows应用程序表单 [英] Excel file into C# Windows application form

查看:73
本文介绍了将Excel文件转换为C#Windows应用程序表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何在Windows窗体应用程序中将Excel文件导入C#。



问候

Balamurugan

Hi,
How to Import Excel file into C# in Windows form application.

Regards
Balamurugan

推荐答案

尝试

http://code.msdn.microsoft.com/office/Imoprt-Data-from-Excel-to-705ecfcd [ ^ ]

c#导入和导出代码excel到sql server [ ^ ]


为了查看我们为tis上传的excel文件的内容,我们应该遵循以下代码:

{

OleDbConnection theConnection = new OleDb连接(provider = Microsoft.Jet.OLEDB.4.0; data source = books.xls; Extended Properties = \Excel 8.0; HDR = NO; IMEX = 1; \);

theConnection.Open();

OleDbDataAdapter theDataAdapter = new OleDbDataAdapter(SELECT * FROM [Sheet1
For Viewing the content of the excel file which we uploaded for tis we should follow the below code:
{
OleDbConnection theConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=books.xls;Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");
theConnection.Open();
OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1


,theConnection);

DataSet theDS = new DataSet();

DataTable dt = new DataTable();

theDataAdapter.Fill(dt);

this。 dataGridView1.DataSource = dt.DefaultView;

}



要将Excel文件上传到C#windows应用程序表单,我们应该遵循以下代码:

{

OpenFileDialog fDialog = new OpenFileDialog();

fDialog.Title =选择要上传的文件;

fDialog.Filter =(* .xls)| * .xls;

if(fDialog.ShowDialog()== DialogResult.OK)

{

txtFileName.Text = fDialog.FileName.ToString();

}
", theConnection);
DataSet theDS = new DataSet();
DataTable dt = new DataTable();
theDataAdapter.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}

For uploading a Excel file into C# windows application form we should follow the below code:
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Select file to be upload";
fDialog.Filter = "(*.xls)|*.xls";
if (fDialog.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = fDialog.FileName.ToString();
}


这篇关于将Excel文件转换为C#Windows应用程序表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆