using Excel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; namespace myproject { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DataSet result; private void btnopen_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xlsx", ValidateNames = true }) { if (ofd.ShowDialog() == DialogResult.OK) { FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read); IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(fs); reader.IsFirstRowAsColumnNames = true; result = reader.AsDataSet(); Sheetname.Items.Clear(); foreach (DataTable dt in result.Tables) Sheetname.Items.Add(dt.TableName); reader.Close(); } } } private void Sheetname_SelectedIndexChanged(object sender, EventArgs e) { dataview.DataSource = result.Tables[Sheetname.SelectedIndex]; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)