如何将工作表从vsto工作簿导出到数据集 [英] How can I export a sheet from a vsto workbook to a DataSet

查看:175
本文介绍了如何将工作表从vsto工作簿导出到数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我可以使用OleDb连接将Excel工作表导入数据集.
例如使用以下代码:

Hi, I can import a Excel sheet to an DataSet with an OleDb connection.
For example with this code:

string connstr ="Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\aaa.xls;Extended Properties=Excel 8.0"/>
       OleDbConnection conn = new OleDbConnection(connstr);
       string strSQL = "SELECT * FROM [Sheet$]";

       OleDbCommand cmd = new OleDbCommand(strSQL, conn);
       DataSet ds = new DataSet();
       OleDbDataAdapter da = new OleDbDataAdapter(cmd);
       da.Fill(ds);



但是,当我尝试从VSTO工作簿中的工作表导入时,该工作簿已经打开,因此出现错误.
没有人有一个示例,我如何从VSTO工作簿导入到数据集.
(我要导出到数据集的工作表是VSTO工作簿的成员)

谢谢
Chris



But when I try to import from a sheet in VSTO Workbook the workbook is already open and so I get an error.
Does anyone has an Example how I can import to a Dataset from a VSTO Workbook.
(The sheet that I want to export to a DataSet a member of the VSTO workbook)

Thanks
Chris

推荐答案

; OleDbCommand cmd =新的OleDbCommand(strSQL,conn); DataSet ds = new DataSet(); OleDbDataAdapter da =新的OleDbDataAdapter(cmd); da.Fill(ds);
"; OleDbCommand cmd = new OleDbCommand(strSQL, conn); DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(cmd); da.Fill(ds);



但是,当我尝试从VSTO工作簿中的工作表导入时,该工作簿已经打开,因此出现错误.
没有人有一个示例,我如何从VSTO工作簿导入到数据集.
(我要导出到数据集的工作表是VSTO工作簿的成员)

谢谢
克里斯



But when I try to import from a sheet in VSTO Workbook the workbook is already open and so I get an error.
Does anyone has an Example how I can import to a Dataset from a VSTO Workbook.
(The sheet that I want to export to a DataSet a member of the VSTO workbook)

Thanks
Chris


看看答案中提供的链接,这些链接指向
Take a look at the links provided in the answer to this[^] thread on MSDN.Social.




现在我没有收到错误,但是数据集中什么也没有.这是我的代码:
Hi,

now I don''t get an error, but nothing is in the dataset. Here''s my code:
string strWorkbookName = Globals.ThisWorkbook.FullName;
            string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strWorkbookName + ";Extended Properties=''Excel 12.0;HDR=Yes''";
            OleDbConnection xlConn = new OleDbConnection(strConn);
            string strExcelSheet = Globals.Tabelle1.Name;
            Properties=''Excel 8.0;HDR=Yes;IMEX=1''";
            OleDbDataAdapter xlDA = new OleDbDataAdapter("Select * from [" + strExcelSheet + "


这篇关于如何将工作表从vsto工作簿导出到数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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