S
sara87
Guest
Hi
I have alot of excel files I want to selecte Three files and show them in datagridview,
I tried with code but my code show only the last one, e.g I have 1,2,3 excel files,
datagridview show only the last file 3. What should I do here please.
Thank you!
I tried with this code:
private void Button2_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "XML Files, Text Files, Excel Files|
*.xlsx; *.xls; *.xml; *.txt; "; ;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in openFileDialog1.FileNames)
{
//tb_path is textbox
tb_path.Text = file;
// excelFilePath_com = tb_path.Text;
string constr = string.Format("Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + tb_path.Text + ";Extended Properties = \"Excel 12.0; HDR=Yes;\"; ");
OleDbConnection con = new OleDbConnection(constr);
con.Open();
drop_down_sheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//dro_down_sheet is combobox to choose which sheet to import
drop_down_sheet.DisplayMember = "TABLE_NAME";
drop_down_sheet.ValueMember = "TABLE_NAME";
}
}
Continue reading...
I have alot of excel files I want to selecte Three files and show them in datagridview,
I tried with code but my code show only the last one, e.g I have 1,2,3 excel files,
datagridview show only the last file 3. What should I do here please.
Thank you!
I tried with this code:
private void Button2_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "XML Files, Text Files, Excel Files|
*.xlsx; *.xls; *.xml; *.txt; "; ;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in openFileDialog1.FileNames)
{
//tb_path is textbox
tb_path.Text = file;
// excelFilePath_com = tb_path.Text;
string constr = string.Format("Provider = Microsoft.ACE.OLEDB.12.0; Data Source =" + tb_path.Text + ";Extended Properties = \"Excel 12.0; HDR=Yes;\"; ");
OleDbConnection con = new OleDbConnection(constr);
con.Open();
drop_down_sheet.DataSource = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//dro_down_sheet is combobox to choose which sheet to import
drop_down_sheet.DisplayMember = "TABLE_NAME";
drop_down_sheet.ValueMember = "TABLE_NAME";
}
}
Continue reading...