日期:2014-05-19  浏览次数:20720 次

客户端读取Excel问题~!
怎么样能够让客户在客户端选择excel(不用文件上传到server的方式)然后逐条录入的数据库~,没思路啊谁提个醒~!--关键不知道怎么把文件读进来~!

------解决方案--------------------
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.OleDb " %>
<script language= "VB " runat= "server ">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim strConn As String= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.Mappath( "grade.xls ") & ";Extended Properties=Excel 8.0 " '该句表示连接到Excel文件
Dim conn As New OleDbConnection(strConn) '建立Connection对象
Dim adp As New OleDbDataAdapter( "Select * From [Sheet1$] ", conn) '建立DataAdapter对象
Dim ds As New DataSet() '建立DataSet对象
adp.Fill(ds, "grade ") '填充DataSet对象
MyDataGrid.DataSource=DS.Tables( "grade ").DefaultView '指定数据源
MyDataGrid.DataBind() '执行绑定
End Sub
</script>
<html>
<body>
<h4 align= "center "> 读取Excel文件 </h4>
<asp:DataGrid id= "MyDataGrid " width= "100% " HeaderStyle-BackColor= "#BCBCBC " runat= "server "/>
<body>
</html>