2012-10-15 21 views
0

我使用Microsoft.Office.Interop.Excel;我嘗試使用,以節省用了兼容性97-2003一XLS以下C#interop.excel從不檢查兼容性保存

private void CreationFichier(_Worksheet template, int nom) 
    { 
     _Workbook fichierCree = _excel.Workbooks.Add(); 
     fichierCree.DoNotPromptForConvert = true; 
     fichierCree.CheckCompatibility = false; 

     var feuilleActiveClasseurCree = (_Worksheet)fichierCree.Sheets[1]; 
     string nomFichier = (nom - 4).ToString() + ".xls"; 
     label3.Text = "Creation du fichier "+nomFichier+" ..."; 
     progressBar1.Value++; 
     template.Copy(feuilleActiveClasseurCree); 

     fichierCree.SaveAs(_folderdestination.SelectedPath + "\\" + nomFichier, XlFileFormat.xlExcel8); 
     fichierCree.Close(); 
    } 

但是,這對於檢查了兼容性創建一個彈出 - 我不想要這個彈出。

http://i.stack.imgur.com/8zop9.png

+0

http://stackoverflow.com/questions/12858072/c-sharp-interop-excel-no-check-compatibility-on-save確切重複 – 2012-10-15 06:42:07

+0

是的,但是,它的關閉,沒有找到解決方案!* – user1740962

+0

你檢查http://stackoverflow.com/questions/8879082/how-to-disable-compatibility-check-in-excel-while-automating-through-c-sharp –

回答

0

我沒有找到一個方法來從剛剛代碼解決這個問題,但我發現對我來說有效的解決方案。在我的情況下,我每次打開與模板相同的文件並將其保存爲新文件。使用Office.Interop.Excel._Application.Visible = true我可以更好地看到發生了什麼。我只需從桌面Excel中取出主模板,並在檢查不再顯示此對話框後重新保存它。現在,當我使用該文件作爲模板時,它不再通過詢問保存兼容性的對話框來中斷我的程序。

此外,爲了防止任何文件訪問問題,我做了一個System.IO.File.Copy模板,然後打開並保存我的新文件。

這是一個遲到的答案,可能無法解決您的具體問題。我希望這對任何現在尋找解決方案的人都有幫助。