Data handling in excel

Asked

Viewed 433 times

3

I need to get the generated data from a proc save in any variable that is and make a UPDATE in a worksheet already existing in a fixed path on the system. It is possible to do this process via code ?

Ex. The trial returned these data to me:

inserir a descrição da imagem aqui

Now I would need to store this data somewhere and give a UPDATE in an already created spreadsheet that will stay fixed on a certain path.

  • UPDATE in spreadsheet??? Do you want to change the data of this spreadsheet? Post some spreadsheet lines and show how you want the data received from the trial to change the worksheet data.

  • In this case then you want to pass on this information generated from Procedure, to an (xml, json, etc.) and create a new spreadsheet with this data to replace the fixed worksheet?

  • @Mr_ghost Actually it would be to pass the generated information from the past and to do an Insert in an existing spreadsheet

1 answer

3


Here is an example of code to update a spreadsheet in Excel with C# and ADO:

var connectionStringBuilder = new 
System.Data.OleDb.OleDbConnectionStringBuilder();
connectionStringBuilder.DataSource = @"c:\dev\tmp\consolidated.xlsx";
connectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
connectionStringBuilder.Add("Extended Properties", "Excel 12.0;");

using (var connection = new System.Data.OleDb.OleDbConnection(connectionStringBuilder.ToString()))
{
    connection.Open();
    var updateCommand = connection.CreateCommand();
    updateCommand.CommandText = "update [second$] S inner join [first$] F on S.ID = F.ID set S.Language = F.Language";
    updateCommand.ExecuteNonQuery();
}

Credit for the question

  • +1 The use of ADO is the most recommended

  • @Alexandre Cavaloti, would be able to use data generated from a trial and apply the same with parameter to make an entry in the spreadsheet ?

  • Yes, just open a connection to the database to call the database, save the result and apply in the above solution.

Browser other questions tagged

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