krrishna
krrishna

Reputation: 2078

How to read data from excel like a database table and also update the data on a query based in using VSTO in C#.net?

I am developing an excel addin using C#.net.I have around 200 rows in excel.And i want to read these rows database table records from the Excel and also want to update the any excel column data.

Is there any class which reads data from excel like a data base table and updates the data to excel using the same object ?

Upvotes: 0

Views: 352

Answers (1)

DayDayHappy
DayDayHappy

Reputation: 1679

i am not sure you want to access excel as oledb client using usual db sql. but it seems that you are process it one off, you can then just use the COM object exposed by excel. Add Reference and then at the "COM" tab, choose "Microsoft 5.0 Object Library"

sample below

using Excel = Microsoft.Office.Interop.Excel;

...

        var ExcelApp = new Excel.Application();
        ExcelApp.Visible = true;
        Excel.Workbook wb = ExcelApp.Workbooks.Add();
        // put some data in it
        for (int i = 1; i <= 10; i++)
        {
            ExcelApp.Cells[i, 1] = "Item " + i;

        }


        for (int i = 1; i <= 10; i++)
        {
            Console.WriteLine(ExcelApp.Cells[i, 1].Value);
        }

        Console.ReadKey();

Upvotes: 1

Related Questions