excel连接字符串 [英] excel connection string

查看:66
本文介绍了excel连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想知道如何将Excel 2007连接到C#
请帮助

hey i want to know how to connect the excel 2007 to the c#
please help

推荐答案

此处 [ ^ ]是有用的 CodeProject 为您准备的文章.对于连接字符串,请查看 [
Here[^] is a useful CodeProject article for you. And for connection strings check out this[^]. :)




请按照以下步骤操作
1.在c:\中创建Excel说TEST.xls,并在其中包含一些标题,行和列数据.
2.在excel中创建命名对象",方法是在excel工作簿中选择数据(选择标题和数据),然后转到菜单插入->".名称->定义.为您的对象命名,然后按添加".现在,您有了一个已命名的对象,ADO.NET可以使用该对象进行读取
3.下面是连接到工作簿并绑定到datagridview的代码:)
4. TEST是excel中的命名对象",将其用作表以获取数据

Hi,

Follow the below steps
1. Create Excel say TEST.xls in c:\ with some header and rows and columns data in it.
2. Create "Named Object" in excel by select the data in your excel workbook ( select header and data) and then go to menu Insert --> Names --> Define. Name your object and press "Add" Now you have an named object which can be used to read by ADO.NET
3. Below is the code to connect to workbook also to bind to datagridview :)
4. TEST is your "Named Object" in excel use it as table to get data

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=Excel 8.0");
            OleDbDataAdapter da = new OleDbDataAdapter("select * from TEST", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;


这篇关于excel连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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