Share via

Interop Excel

Davi Sabaneli 1 Reputation point
2020-08-18T22:03:12.86+00:00

Parece que Microsoft esta alterando o forum, me jogou pra ca e so tem em ingles ...

Pessoal, desenvolvi uma aplicação que exporta do SQL, Access, SQLite para excel que esta funcionando blz ... mas quando eu instalo em um computador que nao tem officce nao funciona ... Marquei para copiar a DLL com o projeto, mas mesmo assim nao funciona, até fecha a aplicacao.

O mesmo ocorre com o Access, diz que o driver OleDB nao esta instalado ... sera que vou ter esse prpoblema direto? ou teria como copiar tudo que precisa junto com a aplicação quando instalar?

Obrigado!

Community Center | Not monitored
0 comments No comments

2 answers

Sort by: Most helpful
  1. David 151 Reputation points
    2021-05-17T06:29:12.17+00:00

    Hi, I suggest that you try Spire.XLS for .NET. It is a standalone class library for Excel documents which does not require MS Excel to be installed on servers or clients' machines. Moreover, exporting data from database to Excel is quite straightforward.

    //connect database
    OleDbConnection connection = new OleDbConnection();
    connection.ConnectionString = @"Provider=""Microsoft.Jet.OLEDB.4.0"";Data Source=""demo.mdb"";User Id=;Password="
    OleDbCommand command = new OleDbCommand();
    command.CommandText = "select * from parts";
    DataSet dataSet = new System.Data.DataSet();
    OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command.CommandText,connection);
    dataAdapter.Fill(dataSet);
    DataTable t = dataSet.Tables[0];
    //export datatable to excel
    Workbook book = new Workbook();
    Worksheet sheet = book.Worksheets[0];
    sheet.InsertDataTable(t, true, 1, 1);
    book.SaveToFile("insertTableToExcel.xlsx",ExcelVersion.Version2013);
    

    Was this answer helpful?

    0 comments No comments

  2. Anonymous
    2020-08-18T23:02:03.503+00:00

    QnA forums are currently English only. The migration notification you're seeing is in error. Only the English TechNet / MSDN forums are currently in migration. You can disregard notice, they're actively answering question in dedicated forums here.

    https://social.technet.microsoft.com/Forums/pt-br/home
    https://social.msdn.microsoft.com/Forums/vstudio/pt-BR/home

    --please don't forget to Accept as answer if the reply is helpful--

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.