打开Excel文件并将其作为上下文响应返回 [英] Opening Excel file and returning it as context response

查看:103
本文介绍了打开Excel文件并将其作为上下文响应返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想做的事情:
-用户单击asp.net页(C#)上的一个按钮
-打开Excel文件
-编辑文件的内容
-返回excel文件供用户下载

我找到了一种打开excel文件并编辑内容的方法(我用用户在单击按钮之前输入的某些文本替换了[[%customer_name%]]之类的东西).但是我不确定如何将excel文件返回到context.Response中,以便可以提示用户下载excel文件.

我该怎么办?

在此先要多谢,如果在此之前有人问过,我深表歉意..我只是找不到它..

Here''s what i''m trying to do:
- User clicks a button on the asp.net page (C#)
- Open an excel file
- Edit the content of the file
- Returning the excel file for user to download

I have found the way to open the excel file and edit the content (I''m replacing things like "[%customer_name%]" with some text that the user input before clicking the button). But i''m not sure how to have the excel file being returned into the context.Response, so that the user can be prompted to download the excel file.

How do i do that?

Many thanks in advance, and apologies if this has been asked before.. i just couldnt find it..

推荐答案

要在.net中下载文件并不难

To download a file in .net is not that hard

//Set appropriate ContentType.
Response.ContentType = "Application/xls";

string fileh = MapPath("myFile.xls");

//Write the file to the output stream.
Response.WriteFile(file);


这篇关于打开Excel文件并将其作为上下文响应返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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