2011-03-21 34 views
1

我們的應用程序之一允許用戶使用Excel模板(使用Click Once安裝/部署)生成Excel文件。這是一個VSTO應用程序。VTSO:有時用戶無法打開由C#Winform App生成的Excel文件

Excel文件是由註冊表存儲一些價值觀和「呼喚」 genereted使用下面的代碼(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的一般新手。我有點不清楚的是文件如何變得sa VED。我假設它被保存時,模板中的所有相關「代碼」都不會與文件一起保存,只會保存數據...

偶爾,我們的用戶無法打開文件。 Excel永遠不會給出錯誤,它只是像試圖打開文件一樣「旋轉」。我們等了30分鐘或更長時間,沒有結果。它「似乎」像文件被打開,但從未「繪製」(呈現),但這只是一個猜測。這是非常隨機的。有時候,其他用戶可以打開同一個文件,有時候有問題的用戶可以稍後重試,文件打開就好。

我們有幾個「想法」是什麼可能導致問題從:防病毒到網絡共享。雖然,這是一個隨機問題,我們不知道如何在發生這種情況時進行調試(它可能不會再發生數小時或數天)。用戶報告說,他們沒有打開任何其他Excel文件的問題,只有這個應用程序生成的文件。

有沒有人有任何想法可能會導致這?

Shayne

+2

您是否關閉了excel文件?你需要釋放excel對象。你可以把你的連接放在使用聲明中嗎?請參閱http://stackoverflow.com/questions/4980467/export-dataset-to-excel – WorldIsRound 2011-03-21 19:50:03

+0

我的代碼完全錯誤。它調用一個不同的代碼區域的Excel模板....我會更新主要問題 – Shayne 2011-03-21 21:13:42

回答

0

我對這個問題的描述是完全錯誤的。今天第一手看到問題後。問題是文件打開,但不可見。我將開始一個更好地描述問題的新線程。

+0

你可以引用該線程嗎? – KronoS 2012-07-17 18:42:50