[英]Exception trying read an excel file by OleDb?
我正在尝试使用OleDb
读取Excel文件,但总是会引发异常。 我该怎么办?
试
private void btnRead_Click(object sender, EventArgs e) {
try {
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
FILE_PATH + ";Extended Properties=\\Excel 8.0;HDR=YES;IMEX=1\"");
String sql = "select * from [alunos.unid2.xls$]";
OleDbCommand command = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader rs = command.ExecuteReader();
while (rs.NextResult()) {
//Console.WriteLine(rs["ALU_NOME"]);
strBuilder.Append(rs["ALU_NOME"]);
}
conn.Close();
}catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
例外
Format of the initialization string does not conform to specification starting at index 130.
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FILE_PATH + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'");
您缺少Extended Properties
值的开头报价
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.