如何通过C#创建连接字符串到Excel工作表2007 [英] How to create connection string to excel sheet 2007 by C#

查看:136
本文介绍了如何通过C#创建连接字符串到Excel工作表2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道这个连接字符串是excel是错误的还是真的



  public   static   string  fileName =  string .Format(  {0} \\Book502,Directory.GetCurrentDirectory() ); 

string connection = string .Format( Provider = Microsoft.ACE.OLEDB.12.0; + < span class =code-string> Data Source = {0}; Mode = ReadWrite; Extended Properties ='Excel 12.0 Xml; HDR = YES',fileName);





我的档案簿502

有两张



第1页


i插入数据并更新并从中读取数据



它有以下栏目



ID INTEGER



用户名字符(255)



国家字符(255)



第2页有以下栏目



ID INTEGER



会员名字字符(255)



意味着所有两张床单都有文字除了ID



ALSO文件在标题中有列



进程两张纸插入更新阅读选择



交易大小我将使用5000行



3 USER将使用excel表格



以便excel文件的格式正确吗?



格式我写得好吗?

但我真的需要我指定的IMEX = 0或1或2

HDR = YES或NO




我的尝试:



如何通过c#创建连接字符串到excel工作表2007 

解决方案

你好,



您可以参考此链接,我认为它对您有所帮助。



如何使用C#中的连接字符串读取Microsoft Excel 2007 [ ^

请参阅使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ]。


I need to know are this connection string to excel is wrong or true

public static  string  fileName = string.Format("{0}\\Book502", Directory.GetCurrentDirectory());

string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0};Mode=ReadWrite;Extended Properties='Excel 12.0 Xml;HDR=YES'", fileName);



my file book 502
have two sheets

sheet 1

i insert data and update and read data from it

it have following column

ID INTEGER

User Name char(255)

Country char(255)

sheet 2 have following columns

ID INTEGER

Member Name char(255)

meaning all two sheets have text except ID

ALSO file have column in header

processes of two sheets insert update read select

size of transaction i will use 5000 rows

3 USER will use excel sheet

so that what correct format to excel file ?

the format i write working good ?
but really i need what i assign IMEX=0 or 1 or 2
HDR = YES OR NO


What I have tried:

How to create connection string to excel sheet 2007 by c#

解决方案

Hello,

You can refer this link, i think it's helpful for you.

How to Read Microsoft Excel 2007 Using a Connection String in C#[^


See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].


这篇关于如何通过C#创建连接字符串到Excel工作表2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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