如何将excel文件上传到服务器并从服务器下载 [英] how to upload excel file to server and download from server

查看:97
本文介绍了如何将excel文件上传到服务器并从服务器下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我真的很空白,没有找到解决我的问题的方法.我想创建一个网页,其中包含一个页面,允许用户将excel文件上传到服务器.然后我要显示excel文件,以便其他用户可以查看或下载该文件.

我真的希望有人能对此提供帮助.这真的很紧急,因为这是完成我的项目的最后一页.截止日期临近.

在此先感谢.
musiw.

Hi all,

i really blank and found no solution to my problem. i want to create a webpage which has a page that allows user to upload excel file to server.then i want to display the excel file so that other user can view or download the file.

i really hope anyone can help me on this.its really urgent as this is the last page to complete my project.the deadline is near.

thanks in advance.
musiw.

推荐答案

1.使用fileupload 控件将文件上传到服务器的虚拟目录中.
2.上传完成后,使用ADO.NET调用将excel读入datatable (详细信息如下)
3.准备好datatable 并将其标记为gridviewdatasource .

要将excel读入datatable ,请尝试以下操作(在connectionstring
中更改excel路径
1. use the fileupload control to upload the file in a virtual directory of server.
2. Once the upload is done read the excel into a datatable using ADO.NET calls (details below)
3. Once you have datatable ready mark this as the datasource for your gridview.

To read the excel into datatable Try this (change excel path in connectionstring
OleDbConnection con = null;
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\testExcel.xls;Extended Properties='Excel 8.0;HDR=YES;'";

con = new OleDbConnection(connectionString);
            con.Open();
 
            if (con.State == ConnectionState.Open)
            {
                OleDbCommand cmd = con.CreateCommand();
                cmd.CommandText = "Select * from [Sheet1


" 中选择* ; cmd.CommandType = CommandType.Text; OleDbDataAdapter da = OleDbDataAdapter(cmd); DataTable table = DataTable(); da.Fill(表); }
"; cmd.CommandType = CommandType.Text; OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataTable table = new DataTable(); da.Fill(table); }


完成此操作后,您可以使用此数据表对象将数据放在UI或任何数据库表中的任何位置.


Once this is done you can use this datatable object to put the data anywhere be it UI or any DB table.


hai,
试试这个
首先插入文件上传控件
在根目录中创建一个名为"SomeFolderName"的文件夹,并使用时间和文件名保存excel文件
创建一个查询以从excel获取详细信息并将其保存在数据表"dt"中

您可以使用默认的getExcelTable函数..jus您需要更改连接名称


hai,
try this
first insert a file upload control
create a folder in root as "SomeFolderName" and save the excel file with time and filename
create a query to fetch the details from excel and save it in datatable "dt"

you can use the getExcelTable function default..jus u need to change the connection name


<pre lang="vb">
Dim filename As String = Path.GetFileName(FileUpload.FileName)

                filepath = "\SomeFolderName\" & Now.Date().ToString("Mdy") & "_" & filename

                FileUpload.SaveAs(Server.MapPath("~/") & filepath)

                strsql = "select   [Col1name]," & vbCrLf & _
"[Col2name]  from [Sheetname


这篇关于如何将excel文件上传到服务器并从服务器下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆