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

推荐订阅源

腾讯CDC
Schneier on Security
Schneier on Security
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
A
About on SuperTechFans
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
V2EX - 技术
V2EX - 技术
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
V
Visual Studio Blog
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
Scott Helme
Scott Helme
H
Heimdal Security Blog
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Vulnerabilities – Threatpost
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
Jina AI
Jina AI
S
Securelist
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
AWS News Blog
AWS News Blog
N
News and Events Feed by Topic
博客园 - 三生石上(FineUI控件)
量子位

博客园 - 小乔的闺房

学习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'";