简体   繁体   English

C#interop.excel从不检查兼容性

[英]C# interop.excel never check compatibility on save

I use the Microsoft.Office.Interop.Excel ; 我使用Microsoft.Office.Interop.Excel ; I try to save a XLS with compatibilty 97-2003 using the following 我尝试使用以下命令保存具有兼容性97-2003的XLS

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

But this creates a popup for checking the compatibilty - I don't want this popup. 但这会创建一个用于检查兼容性的弹出窗口-我不希望出现此弹出窗口。

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

I did not find a way to fix this issue from just code but I did find a solution that works for me. 我没有找到仅通过代码解决此问题的方法,但确实找到了适合我的解决方案。 In my case I am opening the same file as a template each time and saving it out as a new file. 就我而言,我每次都打开与模板相同的文件,并将其另存为新文件。 With Office.Interop.Excel._Application.Visible = true I can see better what is happening. 使用Office.Interop.Excel._Application.Visible = true,我可以更好地了解正在发生的事情。 I simply took the master template from my desktop Excel and re-saved it after checking the the don't show this dialog for this box again. 我只是从桌面Excel中获取了主模板,然后选中了“不再显示此对话框”对话框,然后重新保存了它。 Now when I use the file as a template it no longer interrupts my program with the dialog asking about saving for compatibility. 现在,当我将文件用作模板时,它不再通过询问保存兼容性的对话框打断程序。

Also, to prevent any file access issues I do a System.IO.File.Copy of the template and then open and save my new file. 另外,为防止出现任何文件访问问题,我对模板做了System.IO.File.Copy,然后打开并保存我的新文件。

This is a late answer and may not solve your specific issue. 这是一个较晚的答案,可能无法解决您的特定问题。 I hope it is a help to anyone searching for a solution now. 我希望这对现在正在寻找解决方案的任何人都是有帮助的。

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

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