读取Excel文件时出错 [英] Error While Reading Excel File

查看:85
本文介绍了读取Excel文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


尝试读取Excel文件时收到此错误.
外部表的格式不正确"

Hi,
I got this error while I tried to read an Excel file .
"External table is not in the expected format"

public static DataTable GetExcelData(string strFile)
{
  DataTable dttblExcelData = new DataTable();
  try
  {
    string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFile+ ";" + "Extended Properties=''Excel 8.0;IMEX=1''";

    OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [" + strFile+ "]", strConn);

    myCommand.Fill(dttblExcelData);
  }
  catch (Exception e)
  {
    string  errMsg = e.Message.ToString();
  }
  return dttblExcelData;
}

推荐答案

我确定您可以在Google搜索的第一页上找到解决方案.我发现这些有答案

Excel外部表未采用预期格式." [ ^ ]

外部表的格式不正确. [
I''m sure you can get the solution in 1st page of Google search. I found these which has answers

Excel "External table is not in the expected format."[^]

External table is not in the expected format.[^]


这篇关于读取Excel文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆