外部表格不是预期的格式

外部表格不是预期的格式

本文介绍了外部表格不是预期的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用下面显示的代码读取Excel(.xlsx)文件。错误是....外部表格不是预期的格式。



我的尝试:



I'm trying to read an Excel (.xlsx) file using the code shown below.Error is.... External table is not in the expected format.

What I have tried:

DataTable dtData = new DataTable();
        OleDbConnection oOleDbConnection;
        OleDbDataAdapter oOleDbDataAdapter;
        try
        {
            oOleDbConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0';");
            oOleDbDataAdapter = new OleDbDataAdapter("select * from [sheet1$]", oOleDbConnection);
            oOleDbDataAdapter.Fill(dtData);
            oOleDbConnection.Close();
            oOleDbConnection.Dispose();
            return dtData;
        }
        catch (Exception ex)
        {
            return null;
        }









你能告诉我在哪里我错了..





Can you please tell me where I went wrong..

推荐答案









能告诉我吗哪里出错了..





Can you please tell me where I went wrong..



oOleDbConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0';");
oOleDbConnection.Open(); //you missed that!
oOleDbDataAdapter = new OleDbDataAdapter("select * from [sheet1


这篇关于外部表格不是预期的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:28