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();
}
查看全文
相关阅读:
proxool数据库连接池用法
SQL Server 用链接server 同步MySQL
使用DNSCrypt解决Dropbox污染问题
POJ 1952 BUY LOW, BUY LOWER DP记录数据
使用doxygen为C/C++程序生成中文文档
构造器(二)----指定构造器、便利构造器
Spring Boot 部署与服务配置
排序算法c语言描述---冒泡排序
【转】Android Studio系列教程一--下载与安装
【转】Windows环境下Android Studio v1.0安装教程
原文地址:https://www.cnblogs.com/pw/p/583890.html
最新文章
java实现迷宫算法--转
归并排序
快速排序
动态规划之矩阵连乘问题
DP之矩阵连乘问题
Trie 树 及Java实现
求二叉树中的节点个数、求二叉树的深度(高度)
通过Gradle来下载依赖的jar包
七牛
微信公众号 图文信息
热门文章
如何通过使用fiddler对Android系统设备抓包总结
小程序开发
查看oracle数据库的启动时间
oracle取随机结果测试
PLSQL乱码&TNS-12557: protocol adapter not loadable解决
wscript shell
wmic linux python
jQuery插件AjaxFileUpload实现ajax文件上传时老是运行error方法 问题原因
程序猿正本清源式进化的意义
BZOJ 2245 SDOI 2011 工作安排 费用流
Copyright © 2011-2022 走看看