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 xml_parser_create_ns() 函数
PHP xml_parse_into_struct() 函数
PHP xml_parse() 函数
PHP xml_get_error_code() 函数
PHP xml_get_current_line_number() 函数
文本竖排组合 | text-combine-upright (Writing Modes)
文本溢出 | text-overflow (Basic User Interface)
文本渲染 | text-rendering (Scalable Vector Graphics)
文本最终对齐 | text-align-last (Text)
文本属性-风格 | text-emphasis-style (Text Decoration)
原文地址:https://www.cnblogs.com/pw/p/583890.html
最新文章
2018-8-10-WPF-好看的矢量图标
2019年2月5日训练日记关于int字节数,long int 字节数的讨论
2019年2月5日训练日记关于int字节数,long int 字节数的讨论
2019/02/03训练日记
2019/02/03训练日记
雪耻题
雪耻题
2019/02/02训练日记
2019/02/02训练日记
疯子的算法总结(六) 简单排序总 选择排序+插入排序+比较排序+冒泡排序
热门文章
Java实现 LeetCode 1111 有效括号的嵌套深度(阅读理解题,位运算)
Java实现 LeetCode 1111 有效括号的嵌套深度(阅读理解题,位运算)
Java实现 LeetCode 1111 有效括号的嵌套深度(阅读理解题,位运算)
Java实现蓝桥杯凑算式(全排列)
Java实现蓝桥杯凑算式(全排列)
Java实现蓝桥杯凑算式(全排列)
JavaScript实现登录滑动验证
JavaScript实现登录滑动验证
JavaScript实现登录滑动验证
ASP.Net Web中Repeater怎么删除指定行
Copyright © 2011-2022 走看看