没有打开excel文件 [英] Not opening excel file

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

问题描述

我的代码是

My code is

string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            
            string path = FileName;
            oXL = new Microsoft.Office.Interop.Excel.Application();
            oXL.Visible = true;
            oXL.DisplayAlerts = false;
            Workbooks workbooks = oXL.Workbooks;
            mWorkBook = workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);





我尝试了什么:



我收到错误,当我尝试打开Excel文件时,显示错误 - >

抱歉,我们找不到Book1.xlsx。它是否可能被移动,重命名或删除?



What I have tried:

I am getting error, when I try to open Excel file, Its showing error -->
Sorry, we couldn't find Book1.xlsx. Is it possible it was moved, renamed or deleted?

推荐答案

哦,男孩。从哪里开始?



首先, PostedFile <的 FileName 属性/ code> object只是客户端上文件的名称。您的代码正在服务器上执行 。你不能只是从服务器打开那条路径,因为它不存在。



如果你想对服务器上的文件做一些事情,你要么需要使用 SaveAs 方法将其保存到服务器,或者读取 InputStream 以访问原始文件字节。 br />


其次,您的代码正在服务器上执行。如果您打开一个Excel实例,它将在服务器上打开,没有人会看到它。这假设你已经在服务器上安装了Excel,并且已经跳过了这篇Microsoft知识库文章中记录的所有箍:

Oh boy. Where to start?

First of all, the FileName property of the PostedFile object is just the name of the file on the client. Your code is executing on the server. You can't just open that path from the server, because it doesn't exist.

If you want to do something with the file on the server, you either need to save it to the server with the SaveAs method, or read the InputStream to access the raw file bytes.

Secondly, your code is executing on the server. If you open an instance of Excel, it will open on the server, where nobody will ever see it. And that's assuming you have Excel installed on the server, and have jumped through all the hoops documented in this Microsoft Knowledgebase article:
< a href =https://support.microsoft.com/kb/257757>服务器端Office自动化的注意事项 [ ^ ]



Microsoft目前不推荐,也不支持任何无人值守的Microsoft Office应用程序自动化,非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务),因为Office在此环境中运行时可能会出现不稳定的行为和/或死锁。


Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.





你需要回到基础并了解网站的运作方式,以及客户和<之间的区别b>服务器


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

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