在 WinForm中打开Excel
添加 openFileDialog(openFileDialogSource) 和 toolStrip 和ComboBox(ctlPath) 控件
//代码:
DataTable dTable;
// 打开
private void buttonOpen_Click(object sender, EventArgs e)
{
if (openFileDialogSource.ShowDialog()==DialogResult.OK)
{
ctlPath.Text = openFileDialogSource.FileName;
ExceltoDataSet(ctlPath.Text);
}
}
//打开方法
public DataTable ExceltoDataSet(string path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
System.Data.DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
string tableName = schemaTable.Rows[0][2].ToString().Trim();

本文介绍如何在C#的WinForm应用中使用控件openFileDialog和ComboBox来读取及选择Excel文件。
最低0.47元/天 解锁文章
1103

被折叠的 条评论
为什么被折叠?



