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();
}
查看全文
相关阅读:
XXX系统讨论
问题账户需求分析
2017年秋季个人阅读计划
《软件工程概论》的评价
第二阶段Day10
每周总结16
假期学习记录13(ImageView实现动态加载网络图片)
假期学习记录12(android与web服务器之间的list/json数组的消息传递)
假期学习记录11(NavigationView点击事件无效)
假期学习记录10(自定义AlertDialog,按钮关闭AlertDialog)
原文地址:https://www.cnblogs.com/pw/p/583890.html
最新文章
关于date的转换问题
Java Junit单元测试步骤总结
一个简单的登录例子去理清分层思路
关于线程的synchronized,wait,sleep,notify的一段有趣的代码
静态变量与实例变量的区别
我们的项目
咱们的team1序章
2020寒假(9)
2020寒假(8)
2020寒假(7)
热门文章
2020寒假(6)
2020寒假(4)
2020寒假(3)
2020寒假(2)
2020寒假(1)
数据清洗
一步一步用Jsp+Javabean+Servlet实现登录功能
03软件需求模式阅读笔记之三
02软件需求模式阅读笔记之二
01软件需求模式阅读笔记之一
Copyright © 2011-2022 走看看