zoukankan
html css js c++ java
Excel的导出操作
下面的代码展示了如何将Excel内容显示到GridView中:
aspx代码:
.aspx
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeBehind
=
"
Default.aspx.cs
"
Inherits
=
"
TCQA.Web._Default
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
操作Excel
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
input
type
="file"
id
="f_path"
runat
="server"
/>
<
asp:Button
ID
="btnImport"
runat
="server"
Text
="导入"
OnClick
="btnImport_Click"
/>
<
asp:GridView
ID
="gv_list"
runat
="Server"
AutoGenerateColumns
="true"
>
</
asp:GridView
>
</
form
>
</
body
>
</
html
>
.cs代码:
protected
void
btnImport_Click(
object
sender, EventArgs e)
{
string
Path
=
f_path.Value;
string
strConn
=
"
Provider=Microsoft.Jet.OLEDB.4.0;
"
+
"
Data Source=
"
+
Path
+
"
;
"
+
"
Extended Properties=Excel 8.0;
"
;
OleDbConnection conn
=
new
OleDbConnection(strConn);
conn.Open();
string
strExcel
=
""
;
OleDbDataAdapter myCommand
=
null
;
DataSet ds
=
null
;
strExcel
=
"
select * from [sheet1$]
"
;
myCommand
=
new
OleDbDataAdapter(strExcel, strConn);
ds
=
new
DataSet();
myCommand.Fill(ds,
"
table1
"
);
gv_list.DataSource
=
ds;
gv_list.DataBind();
}
查看全文
相关阅读:
php 上传大文件问题
两台虚拟机实现负载均衡
lnmp一键安装包搭建lnmp环境
PHPExcel在读取时时间的处理
ZeroMQ研究与应用分析
堆排序(概念、原理、实现)
HASH表的实现(拉链法)
加密和数字签名工具GPG
我的2014 一言难尽
MySQL优化之profile
原文地址:https://www.cnblogs.com/pw/p/583890.html
最新文章
hdu 4336 Card Collector —— Min-Max 容斥
bzoj 2839 集合计数 —— 二项式反演
CF gym 101933 K King's Colors —— 二项式反演
UOJ #54 时空穿梭 —— 计数+莫比乌斯反演+多项式系数
关于 Capella 需要纠正的语音
转型公告
[Luogu 2023] AHOI2009 维护序列
[Luogu 2486] SDOI2011 染色
[Luogu 1196] NOI2002 银河英雄传说
[BZOJ 2438] 中山市选2011 杀人游戏
热门文章
[Luogu 1351] NOIP2014 联合权值
[Luogu 2024] 食物链
[Luogu 1197] JSOI2008 星球大战
「网络流24题」 12. 软件补丁问题
Mysql数据库主从配置及原理
linux下vim常用命令多行注释和多行删除
linux服务器内存溢出,删除无关文件!
linux下搭建svn服务器
阿里云服务部署gogs代码管理系统
新建ftp用户并指定访问目录
Copyright © 2011-2022 走看看