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();
}
查看全文
相关阅读:
国外保健品品牌介绍
海淘第一单
表查询语句与方法
表与表关系
表完整性约束
表字段数据类型
存储引擎
数据库之MySQL基本操作
MAC重置MySQL root 密码
进程池、线程池、协程
原文地址:https://www.cnblogs.com/pw/p/583890.html
最新文章
mysql --- select ...for update
mysql -- exists 替换 in
Nginx/LVS/HAProxy负载均衡软件的优缺点详解
Java NIO原理和使用
Java多线程程序设计小记
MySQL数据库分表分区(一)(转)
SHOW PROFILE
mysql 性能优化方案 (转)
java整体集合框架(转)
JVM内存管理
热门文章
深入研究 Java Synchronize 和 Lock 的区别与用法
Java 连接池的工作原理
JMS学习的个人理解笔记
Amazon全场满$35减$5 (需Facebook)
营养补充剂选购
护眼营养补充剂之叶黄素
关节和骨骼健康
膳食补充剂
购物返利
Amazon教程:刚买就降价!避免损失,申请PRICE MATCH(价格保护)的方法
Copyright © 2011-2022 走看看