我使用 c# 创建了一个 asp.net 网站。单击按钮时,网页中的值将存储到系统中的 Excel 表中。
这在本地完成时工作正常,但是当从客户端计算机访问 Intranet 时,它会显示错误消息:
"file path is invalid or the file is already open"
如何使excel表打开并将数据保存在客户端机器中?
我的代码:
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;