Hello,
I need to populate a Combo Box with sheet names in an Excel File.
I Have an openfiledialog that i search for the excel file and put the dirPath to a textbox, now i need to populate the ComboBox with the sheets in that file,
the idea is so when i select the second sheet which could be name (cities) in the ComboBox, i can pass that sheet name to the string for processing.
thanks
I need to know what to stick in here.
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Excel Worksheets|*.xls;*.xlsx"; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.filePath1.Text = openFileDialog1.FileName; } } private void button2_Click(object sender, EventArgs e) { string pathCon = "Provider=Microsoft.Ace.OLEDB.12.0; Data Source=" + filePath1.Text + ";Extended Properties=\"Excel 8.0; HDR=Yes;\";"; OleDbConnection conn = new OleDbConnection(pathCon); OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from [" + sheetSelect.Text + "$]", conn); DataTable dt = new DataTable(); myDataAdapter.Fill(dt); dataGridView1.DataSource = dt; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } }This right now has a button I click that allows me to import the xls and or xlsx file. I have a textbox area where at the moment I type in the sheet name. I want to be able to select the sheet name from a combobox that gets populated. I think I'm describing this correctly.
If there are additional libraries that I need to put in also.. that info would be helpful too. Thanks