Reading of Excel file

Asked

Viewed 310 times

3

I’m trying to use the 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’m trying to read has six columns, when I run this code, it’s only stored in the Dataset 5 columns. I’ve looked at a lot of ways to do the same thing and it’s always the same mistake.

  • What mistake you’re making?

  • none, does the whole process without error charging none, but in the end it does not bring all the information from excel file

1 answer

2

I’ve remade 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.