C#OLEDBConnection到Excel [英] C# OLEDBConnection to Excel

查看:192
本文介绍了C#OLEDBConnection到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  OleDbCommand命令= new OleDbCommand(); 

command = new OleDbCommand(Select * from [working sheet $],oleDBConnection);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
dataAdapter.SelectCommand = command;

dataAdapter.Fill(dt);

有没有类似的方法,我可以简单地将datatable复制回Excel表?我发现的例子是按照单元格复制,但是大数据集可能会显着减慢。



谢谢

解决方案

您正在寻找 DataAdapter.Update 方法,它将DataTable中所做的任何更改应用于数据库(在这种情况下为电子表格)


I am copying an Excel sheet into a Datatable as such:

OleDbCommand command = new OleDbCommand();

            command = new OleDbCommand("Select * from [working sheet$]", oleDBConnection);
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
            dataAdapter.SelectCommand = command;

            dataAdapter.Fill(dt);

Is there a similar method where I can just simply copy the datatable back to an Excel sheet? The examples I keep finding are copying cell by cell, but this can be noticably slow with large data sets.

Thanks

解决方案

You're looking for the DataAdapter.Update method, which applies any changes made in the DataTable to the database (or spreadsheet, in this case)

这篇关于C#OLEDBConnection到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆