简体   繁体   中英

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

One of our applications allows users to generate an Excel file using an Excel Template (that is installed/deployed using Click Once). This is a VSTO application.

The Excel file is genereted by storing some values in the registry and "calling" the template using the following code (the coluymns are pulled from two different lists, a "required" list and an "optional list":

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;
    }
}

Then, each template has "a bunch" of code to load the data (using the values in the Registry) into the spreradsheet. (This part never has an issue, it is AFTER the excel file has been saved and someone tries to open it).

I am new to this application and VSTO in general. What I am a little unclear on is how the file gets saved. I assume when it gets saved, all of the associated "code" from the template does NOT get saved with the file, only the data gets saved...

Ocassionally, our users are unable to open the file. Excel never gives an error, it just "spins" like it is trying to open the file. We have waited up to 30 minutes or longer with no results. It "seems" like the file gets opened, but never "painted" (rendered), but that is just a guess. This is very random. Sometimes, the same file can be opened by other users and sometimes the user that had problems can try again later and the file opens just fine.

We have several "ideas" what could be causing the problem from: AntiVirus to Networking shares. Although, it is such a random issue we don't know how to debug this when it happens (it may not happen again for hours or days). The users report they don't have issues opening any other Excel files, only the files generated by this application.

Does anyone have any ideas what could be causing this??

Shayne

My description of this problem was completely wrong. After seeing the problem first hand today. The issue is the file opens, but isn't visible. I am going to start a new thread that better describes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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