Excel file reading

3

I'm trying to use C # to read an Excel file, but every time I run the code the last column is not stored

Reading Code:

        //Cria conexão com a planilha
        OleDbConnection conexao = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminhoParaOArquivo + ";Extended Properties='Excel 12.0 Xml;HDR=YES';");
        //Cria um Adapter para executar o comando Select
        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM [Result$]", conexao);
        //Cria um DataSet para armazenar os dados da consulta
        DataSet ds = new DataSet();
        //Abre a conexão
        conexao.Open();
        adapter.Fill(ds);

The file I am trying to read has six columns, so when I run this code, they are only stored in the DataSet 5 columns. I've tried several ways to do the same thing and it always gives the same error.

    
asked by anonymous 07.01.2016 / 21:06

1 answer

2

Refile your example with the JET driver if you can use it.

string cnnString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;""", caminhoParaOArquivo);
string isql = "select * from [Result$]";

OleDbConnection conn = new OleDbConnection(cnnString);
OleDbDataAdapter adapter = new OleDbDataAdapter(isql, conn);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
conn.Open();
adapter.Fill(ds);
    
19.05.2016 / 21:47