在生产环境中导出Excel不起作用,在本地工作正常 [英] Exporting Excel in Production Env doesn't work, works fine locally

查看:459
本文介绍了在生产环境中导出Excel不起作用,在本地工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在生产环境中运行代码时遇到问题。

我遇到的相同代码我的机器与IIS及其工作正常。



此代码生成带有导出数据的Excel。哪个在本地工作正常,但在生产中它表示突出显示的错误。





404 - 找不到文件或目录。

您要查找的资源可能已被删除,名称已更改或暂时不可用。




帮助将足够好用。

Hi Friends,

I am facing an issue when I run my code in Production Env.
Same code I am running into my machine with IIS and its working fine here.

This code generates the excel with exported data. Which works fine locally, but in production it says the highlighted error.


404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


Help will be appretiated enough.

protected void linkExportExcel_Click(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Cache-Control", "max-age=3");
            Response.AddHeader("Pragma", "public");
            Response.AddHeader("content-disposition", "attachment;filename=LeaveBalanceAsOn(" + DateTime.Now.ToString("MM-dd-yyyy") + ").xls");

            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.xls";
            Response.Write(hidHtml.Value);
            //Response.Write(hidHtml.Value);
            Response.Flush();
            Response.End();
        }

推荐答案

几件事情无法检查:

- Excel正确安装

- 文件实际存在

- 使用正确的工作路径



在你的方法中,你可以使用File.Exists [ ^ ]方法检查文件是否确实存在,如果没有使用正确的方法来传达错误。
Few things to check:
- Excel properly installed
- the file actually exists
- correct working path is used

In your method, you can use File.Exists[^] method to check if the file actually exists and if not use a proper method to communicate the error.


Hi Mika,



谢谢对于你的即时回复问题。



但是你要求我没有在上面的代码中提到任何文件操作,所以这就是我所有的东西已经写过了,我没有使用Introp来创建Excel对象并在Excel.Application对象中添加1行,这是我要避免的事情。 />
我使用了生成.xls文件的conent-disposition,无论服务器中是否安装了excel,bcoz文件需要在客户端打开。



同样的代码在我的办公网站上运行,部署在生产中,我知道这可以通过一些web.config解决方案来解决,但是我在这里需要的更改是什么。



我希望这能让所有人明白,我期待的是什么。
Hi Mika,

Thanks for your instant revert on the question.

But as you have asked i haven't mentioned any file operation in the the above peice of code, so that's all what I have written, i am not using the Introp for creating Excel object and adding 1 by 1 row into the Excel.Application object, this is what I avoid to do.
I have used the conent-disposition which will generate the .xls file irrespective of if there is excel installed in the server or not , bcoz the file needs to be opened at client.

The same piece of code runs in my office site which is deployed in production, I know this could be resolved by some web.config resolution but what are these required changes that I am missing here.

I hope this will make it clear to all, what I am expecting.


这篇关于在生产环境中导出Excel不起作用,在本地工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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