如何下载excel文件 [英] How to download excel file

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

问题描述

您好,



我使用 Microsoft.Office.Interop.Excel 来创建Excel文件。

我可以创建Excel文件,但我想在创建后下载该文件。



我使用 excelworkBook.SaveAs(C:\\Users\\Test\\Desktop\\testExceldata.xlsx);



代替我想下载文件。



任何人都可以帮我这个。



问候,

Viprat

Hello,

I am using Microsoft.Office.Interop.Excel to create the Excel file.
I am able to create the Excel file but i want to download that file after create.

I used excelworkBook.SaveAs("C:\\Users\\Test\\Desktop\\testExceldata.xlsx");

In place of that i want to download the file.

Can anyone help me on this.

Regards,
Viprat

推荐答案

1-在.aspx文件中添加Hyper Link,如:

1- Add Hyper Link in your .aspx file like:
<asp:hyperlink id="HyperLink1" runat="server">Download</asp:hyperlink>





2-在后面的代码中将导航URL分配给超链接当您保存工作簿时。



2- Assign the Navigate URL to your Hyperlink in code behind When you saving your workbook.

HyperLink1.NavigateUrl = "your generated file location";


不要使用Excel互操作,asp.net不支持它,并且非常不可靠。要将文件发送到客户端,有几种方法



http://stackoverflow.com/questions/14566781/correct-usage-of-asp-net-response-transmitfile-and-response-end [ ^ ]



http://stackoverflow.com/questions/19079591/asp-net-download-file-using-httpcontext-current-response-transmitfile-in-asp-net [ ^ ]
Don't use Excel interop, it isn't supported from asp.net and will be very unreliable. To send files to the client there are a few ways

http://stackoverflow.com/questions/14566781/correct-usage-of-asp-net-response-transmitfile-and-response-end[^]

http://stackoverflow.com/questions/19079591/asp-net-download-file-using-httpcontext-current-response-transmitfile-in-asp-net[^]


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

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