繁体   English   中英

VTSO:有时用户无法打开从C#Winform App生成的Excel文件

[英]VTSO: Sometimes users are unable to open Excel file generated from C# Winform App

我们的应用程序之一允许用户使用Excel模板(使用“单击一次”安装/部署)来生成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分钟或更长时间,没有结果。 好像“似乎”打开了文件,但从未“绘制”(呈现),但这只是一个猜测。 这是非常随机的。 有时,其他用户可以打开同一文件,有时遇到问题的用户可以稍后再试,并且文件打开就很好。

我们有几个“想法”可能是导致问题的原因:从防病毒到网络共享。 虽然这是一个随机的问题,但我们不知道如何在发生时对其进行调试(可能在数小时或数天内不会再次发生)。 用户报告他们打开任何其他Excel文件都没有问题,仅打开此应用程序生成的文件。

有谁知道这可能是什么原因?

谢恩

我对这个问题的描述是完全错误的。 今天亲眼看到了问题。 问题是文件已打开,但不可见。 我将开始一个更好地描述问题的新线程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM