【发布时间】:2013-10-18 07:40:28
【问题描述】:
我开发了一个 C# windows 应用程序。它从 excel 文件中读取数据并写入新的 excel 工作簿。为此 WinApp 创建了一个 EXE。如果我从本地机器运行应用程序或 EXE,它工作正常。将新的 Excel 保存到我的 C 盘。我将 msi 和 exe 文件复制到另一台机器并安装了 msi。
从这些机器上运行 exe 时出现以下错误。 “保存文件时出错”。
注意:- 读取文件没有问题。我通过浏览不同类型的文件(如 .jpg、.doc 等)来检查它,在这种情况下,它要求我们浏览相关文件。
我的代码:
existingFileToWrite1 = @"C:\\LeadOwners-IN";
using (packageToWrite1 = new ExcelPackage(existingFileToWrite1))
{
worksheetToWrite.Cells["A1"].Value = "Lead Owners Mail";
worksheetToWrite.Cells["B1"].Value = "TotalLeads-" + sRegion.Trim();
worksheetToWrite.Cells["C1"].Value = sLInfo + "1-" + sRegion.Trim();
worksheetToWrite.Cells["D1"].Value = sLInfo + "2-" + sRegion.Trim();
worksheetToWrite.Cells["E1"].Value = sLInfo + "3-" + sRegion.Trim();
worksheetToWrite.Cells["F1"].Value = sLInfo + "4-" + sRegion.Trim();
worksheetToWrite.Cells["G1"].Value = sLInfo + "5-" + sRegion.Trim();
worksheetToWrite.Cells["H1"].Value = sLInfo + "6-" + sRegion.Trim();
worksheetToWrite.Cells["I1"].Value = sLInfo + "7-" + sRegion.Trim();
worksheetToWrite.Cells["J1"].Value = sLInfo + "8-" + sRegion.Trim();
worksheetToWrite.Cells["K1"].Value = sLInfo + "9-" + sRegion.Trim();
worksheetToWrite.Cells["L1"].Value = sLInfo + "10-" + sRegion.Trim();
worksheetToWrite.Cells["C" + Iteration1].Value = sFull1.Substring(0, sFull1.Length);
worksheetToWrite.Cells["D" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["E" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["F" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["G" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["H" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["I" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["J" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["K" + Iteration1].Value = string.Empty;
worksheetToWrite.Cells["L" + Iteration1].Value = string.Empty;
packageToWrite1.Save();
}
请就此向我提出建议以获得解决方案。 提前致谢。
【问题讨论】:
-
我认为您需要在保存后关闭文档.....并使用 try,catch,finally 块进行正确的错误处理。
-
你的用户在这台机器上有写权限吗?
-
@TheProvost:在 ExcelPackage(existingFileToWrite1) 中,“existingFileToWrite1”是一个参数。上面的行给出了它的值。 (existingFileToWrite1 = @"C:\\LeadOwners-IN";)
-
@user1567896:在我的机器上没有这些权限。
标签: c# excel setup-deployment winapp