简体   繁体   English

如何从excel中读取数据(如数据库表),以及如何基于C#.net中的VSTO在查询中更新数据?

[英]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. 我正在使用C#.net开发一个excel插件。我在excel中大约有200行。我想从Excel中读取这些行的数据库表记录,也想更新任何excel列数据。

Is there any class which reads data from excel like a data base table and updates the data to excel using the same object ? 是否有任何类可以像数据库表一样从excel读取数据并使用同一对象将数据更新为excel?

i am not sure you want to access excel as oledb client using usual db sql. 我不确定您是否要使用通常的db sql作为oledb客户端访问excel。 but it seems that you are process it one off, you can then just use the COM object exposed by excel. 但是似乎您要一次处理它,然后可以只使用excel公开的COM对象。 Add Reference and then at the "COM" tab, choose "Microsoft 5.0 Object Library" 添加引用,然后在“ COM”选项卡上,选择“ Microsoft 5.0 Object Library”

sample below 下面的示例

using Excel = Microsoft.Office.Interop.Excel; 使用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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM