惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 小乔的闺房

学习ID,ClientID,UniqueID 基础知识1 (2)最简单的Remoting程序 (1)将对象序列化为bin,soap,xml (4)迭代器 (3)集合接口 (1)学习数组,集合,IEnumerable接口,引申学习迭代器 (2)学习集合,引申学习索引器和泛型 自定义服务器控件(1)整体把握(未完待续) FindControl实现原理 location详解 使用ASP.NET AJAX实现(图片)幻灯片效果 固定GridView列字符串长度,多于的用...代替 说明nchar(10),char(10),nvarchar(10),varchar(10) syscolumns 获得数据库里所有表的名称 类[属性扩展],属性[属性扩展](待完善) 获得数据库表的列数 WebForm里弹出警告框之内的自定义类MessageBox
读取Excel数据到GridView相关问题(待完善)
小乔的闺房 · 2007-10-12 · via 博客园 - 小乔的闺房

参考文献
http://www.knowsky.com/345281.html

(1)数据读取
Excel表格里的数据如下
 A B C
1 a1 b1 c1
2 a2 b2 c2
3 a3 b3 c3
4 a4 b4 c4
5 a5 b5 c5

select * from [Sheet1$]
读取到的数据如下
a2 b2 c2
a3 b3 c3
a4 b4 c4
a5 b5 c5

select * from [Sheet1$A1:C5]
读取到的数据如下
a2 b2 c2
a3 b3 c3
a4 b4 c4
a5 b5 c5

select * from [Sheet1$A3:C5]
读取到的数据如下
a4 b4 c4
a5 b5 c5

问题一出来了:有效区域内第一行始终读不出来
原因:根据默认连接字符串中,数据提供程序会将有效区域内第一行作为列名(具体显示F1,F2,F3还是其他,有待研究,目前只知道输入汉字则显示汉字)
解决方法:修改连接字符串
默认连接字符串
"provider=microsoft.jet.oledb.4.0;data source=" + @"G:\测试Excel.xls" + ";extended properties='excel 8.0;'"
修改后
"provider=microsoft.jet.oledb.4.0;" + "data source=" + @"G:\测试Excel.xls" + ";extended properties='Excel 8.0;HDR=NO;'"
解释一下:
HDR=NO表示把有效区域内第一行作为数据
HDR=YES表示把有效区域内第一行作为列名

问题二:Excel表格里显示的数据读到GridView里就不一样了
原因:读取文件时,Excel会以第一行的数据类型为参考
解决方法:修改连接字符串
默认连接字符串
"provider=microsoft.jet.oledb.4.0;data source=" + @"G:\测试Excel.xls" + ";extended properties='excel 8.0;'"
修改后
"provider=microsoft.jet.oledb.4.0;" + "data source=" + @"G:\测试Excel.xls" + ";extended properties='Excel 8.0;IMEX=1;'"
解释一下:
IMEX=1来把混合型作为文本型读取

总结:
综合问题一和问题二
连接字符串写成如下方式
"provider=microsoft.jet.oledb.4.0;" + "data source=" + @"G:\测试Excel.xls" + ";extended properties='Excel 8.0;HDR=NO;IMEX=1'";