“保存文件时出错”。运行EXE时抛出异常

时间:2013-10-18 07:40:29

标签: c# excel setup-deployment winapp

我开发了一个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();
}

请就此提出建议以获得解决方案。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

“我的机器中没有这些权限。”

你去吧。可能是安全问题,因为您没有“C:\”目录的正确权限...

嗯尝试运行visual studio作为管理员...右键单击visual studio然后选择以管理员身份运行并查看是否可行

相关问题