Answer 7
Hi Peter,
I've recieved your mail, Thanks.
As the format of your sheet's G column is inconsistent, I suggest you to read the specific range instead of the whole sheet.
The code looks like:
string connectString =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\testit.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"";
OleDbConnection conn = new OleDbConnection(connectString);
OleDbDataAdapter da = new OleDbDataAdapter("Select * From [Sheet1$G19:G45]", conn);
DataTable dt = new DataTable();
da.Fill(dt);
or
conn.Open();
OleDbCommand cmd = new OleDbCommand("Select * From [Sheet1$G19:G45]", conn);
OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
object item = reader.GetValue(0);
textBox1.AppendText(item.ToString() + Environment.NewLine);
}
reader.Close();
HTH.
Thanks.
Figo Fei
MSDN Subscriber Support
in Forum
If you have any feedback on our support, please contact
msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.