我们的一个应用程序允许用户使用Excel模板(使用Click Once安装/部署)生成Excel文件。这是一个VSTO应用程序。
通过在注册表中存储一些值并使用以下代码“调用”模板来生成Excel文件(从两个不同的列表,“必需”列表和“可选列表”中提取coluymns:
private void myButtonExport_Click(object sender, EventArgs e)
{
if (CurrentTableRow == null) return;
if (CurrentTemplateRow == null) return;
List<string> requiredColumns = excelTemplateTableDS.GetColumnsList(false);
List<string> myColumns = userTableDS.GetColumnsList(false);
string selectStatement;
try
{
CustomerListColumnSelect f = new CustomerListColumnSelect(myColumns, requiredColumns);
if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
selectStatement = string.Format("SELECT {0} FROM [{1}]", string.Join(", ", f.SelectedColumns.ToArray()), CurrentTableRow.TableName);
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Company\Collection Development");
rk.DeleteValue("TemplateTableName", false);
rk.DeleteValue("TemplateSelectStatement", false);
rk.SetValue("TemplateTableName", CurrentTableRow.TableName, Microsoft.Win32.RegistryValueKind.String);
rk.SetValue("TemplateSelectStatement", selectStatement, Microsoft.Win32.RegistryValueKind.String);
rk.Close();
// Launch Excel
AppLog.WriteEvent("CreateCustomerList", TraceEventType.Information,
string.Format("Creating customer list [{0}] using table [{1}]", CurrentTemplateRow.TemplateName, CurrentTableRow.TableName));
if (Debugger.IsAttached)
{
FileInfo fi = new FileInfo(CurrentTemplateRow.Path);
string newPath = string.Format(@"C:\Documents and Settings\mpetrie\My Documents\Visual Studio 2010\Projects\Collection Development Templates\{0}\bin\Release\{1}", CurrentTemplateRow.TemplateName, fi.Name);
// If running under DEBUG (and app not installed), then launch latest version
Process.Start(newPath);
}
else
{
Process.Start(CurrentTemplateRow.Path);
}
}
f.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(this, CurrentTemplateRow.Path + "\r\n" + ex.Message, "Process.Start", MessageBoxButtons.OK, MessageBoxIcon.Error);
ResetSteps(sender, e);
return;
}
}
然后,每个模板都有“一堆”代码将数据(使用注册表中的值)加载到spreradsheet中。 (这部分从来没有问题,它是在保存excel文件后有人试图打开它。)
我是这个应用程序和VSTO的新手。我有点不清楚的是如何保存文件。我假设当它被保存时,模板中的所有相关“代码”都不会随文件一起保存,只会保存数据......
偶尔,我们的用户无法打开该文件。 Excel从不给出错误,它只是“旋转”,就像它试图打开文件一样。我们等了30分钟或更长时间没有结果。它似乎“似乎”文件被打开,但从未“绘制”(渲染),但这只是一个猜测。这是非常随机的。有时,其他用户可以打开同一个文件,有时遇到问题的用户可以稍后重试,文件打开就可以了。
我们有几个“想法”可能导致问题:AntiVirus到Networking共享。虽然,这是一个随机的问题,我们不知道如何调试它(它可能不会再发生几个小时或几天)。用户报告他们在打开任何其他Excel文件时没有问题,只有这个应用程序生成的文件。
有没有人有任何想法可能导致这个?
谢恩
答案 0 :(得分:0)
我对这个问题的描述是完全错误的。今天第一手看到问题后。问题是文件打开,但不可见。我将开始一个更好地描述问题的新线程。