无法从Intranet中的客户端计算机打开ms-excel表 [英] unable to open ms-excel sheet from a client machine in the intranet

查看:80
本文介绍了无法从Intranet中的客户端计算机打开ms-excel表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#创建了一个asp.net网站,当点击该按钮时,网页中的值被存储到系统中的Excel工作表中,这在本地完成时工作正常,但是,当从客户端机器访问时在内联网中,它显示错误说:

文件路径无效或文件已经打开,

怎样才能打开Excel工作表和数据保存在客户端机器上?请帮助。

这是我的代码:



Excel._Application myExcelApp;



Excel.Workbooks myExcelWorkbooks;



Excel.Workbook myExcelWorkbook;



// Excel ._Worksheet myExccelWorksheetToChange;



object misValue = System.Reflection.Missing.Value;



myExcelApp = new Excel。应用程序();



myExcelApp.Visible = true;



myExcelWorkbooks = myExcelApp.Workbooks;







String fileName =D:\\marks.xlsx;





myExcelWorkbook = myExcelWorkbooks.Open(fileName,0,true,5,,,true,Excel.XlPlatform.xlWindows,\ t,false,false,0,true);



//字符串名称= System.IO.Path.GetTempPath()+ Guid.NewGuid()。ToString ()+。xlsx;

Excel.Worksheet myExcelWorksheet =(Excel.Worksheet)myExcelWorkbook.ActiveSheet;

// myExcelWorksheet.SaveAs(marks);



String cellFormulaAsString = myExcelWorksheet.get_Range(A2,misValue).Formula.ToString();



myExcelWorksheet.get_Range(A1,misValue)。 Formula = TextBox1.Text;

i have created an asp.net website using c#,when the button is clicked,the values from the webpage are stored into an excel sheet in the system,this works fine when done locally,but,when accessing from the client machine,within the intranet,it shows an error saying:
"file path is invalid or the file is already open",
how can make the excel sheet open and the data be saved in the client machine? pls help.
this is my code:

Excel._Application myExcelApp;

Excel.Workbooks myExcelWorkbooks;

Excel.Workbook myExcelWorkbook;

// Excel ._Worksheet myExccelWorksheetToChange;

object misValue = System.Reflection.Missing.Value;

myExcelApp = new Excel.Application();

myExcelApp.Visible = true;

myExcelWorkbooks = myExcelApp.Workbooks;



String fileName = "D:\\marks.xlsx";


myExcelWorkbook = myExcelWorkbooks.Open(fileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);

// string name = System.IO.Path.GetTempPath()+Guid.NewGuid().ToString()+".xlsx";
Excel.Worksheet myExcelWorksheet = (Excel.Worksheet)myExcelWorkbook.ActiveSheet;
// myExcelWorksheet.SaveAs("marks");

String cellFormulaAsString = myExcelWorksheet.get_Range("A2", misValue).Formula.ToString();

myExcelWorksheet.get_Range("A1", misValue).Formula = TextBox1.Text;

推荐答案

我不确定您是否清楚地了解服务器/客户端架构。你问的不是直接可能的。有间接的方法来实现这一点。



当用户点击按钮时,服务器正在处理该操作。这意味着Excel文件操作也在服务器上完成。 IIS中的每个Web请求都被视为一个独立的进程或会话(除非您进行一些配置更改)。这意味着多个会话正在尝试访问Excel文件,从而导致您获得错误。 Excel打开文件以进行独占访问,防止其他人访问它。



要解决此问题,您需要将Excel文件复制到具有唯一文件的临时存储名称。打开它,保存对它的更改,关闭它并提示用户下载它。
I'm not sure you clearly understand Server/Client architecture. What you are asking is not directly possible. There are indirect ways to achieve this.

When the user clicks the button, the server is processing the action. Which means that the Excel file operations are done on the server as well. Every web request in IIS is treated as an isolated process or session (unless you do some configuration changes). Which means multiple sessions are trying to access the Excel file and hence the error you are getting. Excel opens files for exclusive access preventing anyone else from accessing it.

To get around this issue, you would need to copy the Excel file to temporary storage with a unique file name. Open it, save the changes to it, close it and prompt the user to download it.


这篇关于无法从Intranet中的客户端计算机打开ms-excel表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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