을 사용하여 Excel 파일의 특정 셀을 datagridview로 가져 오는 방법 Excel 파일의 특정 셀을 datagridview의 특정 셀로 가져 오려고합니다.C#
여기 Excel 테이블을 가져 오는 많은 자습서를 따라했지만 Dataagridview의 특정 위치에만 특정 셀만 있으면되므로 코드를 수정했습니다.
대신 : DataGridView1.DataSource = dt;
내가했는데 : dataGridView1.Rows[0].Cells[0].Value = dt;
하지만 작동하지 않습니다.
나를 도와 줄 수 있습니까?
여기
코드입니다 감사 :string constr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + @";Extended Properties=""Excel 12.0 Macro;HDR=YES;ImportMixedTypes=Text;TypeGuessRows=0""";
OleDbConnection con = new OleDbConnection(constr);
//specific cell 1 - product "code"
OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [ARTIGOS$A" + textBox3.Text + ":A" + textBox3.Text + "]", con);
//specific cell 2 - product "description"
OleDbDataAdapter sdb = new OleDbDataAdapter("select * From [ARTIGOS$B" + textBox3.Text + ":B" + textBox3.Text + "]", con);
//specific cell 3 - product "price"
OleDbDataAdapter sdc = new OleDbDataAdapter("Select * From [ARTIGOS$I" + textBox3.Text + ":I" + textBox3.Text + "]", con);
DataTable dt = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
sda.Fill(dt);
sdb.Fill(dt2);
sdc.Fill(dt3);
dataGridView1.Rows.Add();
dataGridView1.Rows[0].Cells[0].Value = dt;
dataGridView1.Rows[0].Cells[1].Value = dt2;
dataGridView1.Rows.Add();
dataGridView1.Rows[0].Cells[2].Value = textBox2.Text;
dataGridView1.Rows[0].Cells[3].Value = dt3;
Excel 파일에서 데이터를 검색하는 데 문제가 있습니까? – Steve