当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Word.SaveAs2方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.SaveAs2方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.SaveAs2方法的具体用法?C# Microsoft.Office.Interop.Word.SaveAs2怎么用?C# Microsoft.Office.Interop.Word.SaveAs2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Word的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Word.SaveAs2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Application_DocumentBeforeSave

        //--- Intercept save handler
        void Application_DocumentBeforeSave(Word.Document doc, ref bool SaveAsUI, ref bool Cancel)
        {
            //Check if this is one of our docs and if it is then do the right thing, not the black and white thing
            //Add a document property so we know that is a contract template and what the id is
            try
            {
                bool hidep = false;
                if (!Globals.ThisAddIn._p.IsVisible)
                {
                    Globals.ThisAddIn.ProcessingStart("Saving");
                    hidep = true;
                }

                string prop = GetCurrentAxiomDocProp();
                if (prop != null)
                {
                    string[] propa = prop.Split('|');
                    if (propa[0] == "ContractTemplate")
                    {
                        Globals.ThisAddIn.ProcessingUpdate("Save Contract Template");

                        // Get the Sidebar and save the elemnt value if that has changed
                        TemplateEdit.TEditSidebar tsb = Globals.ThisAddIn.GetTaskPaneControlTemplate(doc);
                        if(tsb!=null) tsb.FormSave();

                        //save this to a scratch file
                        Globals.ThisAddIn.ProcessingUpdate("Save Scratch");
                        string filename = Utility.SaveTempFile(propa[1]);
                        doc.SaveAs2(FileName: filename, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        //Save a copy!
                        Globals.ThisAddIn.ProcessingUpdate("Save Copy");
                        string filenamecopy = Utility.SaveTempFile(propa[1] + "X");
                        Word.Document dcopy = Globals.ThisAddIn.Application.Documents.Add(filename, Visible: false);
                        dcopy.SaveAs2(FileName: filenamecopy, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        var docclose = (Microsoft.Office.Interop.Word._Document)dcopy;
                        docclose.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(docclose);

                        //Now
                        Globals.ThisAddIn.ProcessingUpdate("Save To SalesForce");
                        _d.SaveTemplateFile(propa[1], filenamecopy);

                        //d.SaveTemplateXML(propa[1], doc.WordOpenXML);

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "ClauseTemplate")
                    {
                        //Save!
                        //doc = Globals.ThisAddIn.Application.ActiveDocument;
                        //d.SaveClauseXML(propa[1],doc.Content.Text ,doc.WordOpenXML);
                        Globals.ThisAddIn.ProcessingUpdate("Save Clause Template");
                        // doc = Globals.ThisAddIn.Application.ActiveDocument;

                        //save this to a scratch file
                        Globals.ThisAddIn.ProcessingUpdate("Save Scratch");
                        string filename = Utility.SaveTempFile(propa[1]);
                        doc.SaveAs2(FileName: filename, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        //Save a copy!
                        Globals.ThisAddIn.ProcessingUpdate("Save Copy");
                        string filenamecopy = Utility.SaveTempFile(propa[1] + "X");
                        Word.Document dcopy = Globals.ThisAddIn.Application.Documents.Add(filename, Visible: false);
                        dcopy.SaveAs2(FileName: filenamecopy, FileFormat: Word.WdSaveFormat.wdFormatXMLDocument, CompatibilityMode: Word.WdCompatibilityMode.wdCurrent);

                        var docclose = (Microsoft.Office.Interop.Word._Document)dcopy;
                        docclose.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(docclose);

                        //Now save the file and then refresh any other docsto reflect the change
                        Globals.ThisAddIn.ProcessingUpdate("Save To SalesForce");
                        _d.SaveClauseFile(propa[1], doc.Content.Text, filenamecopy);

                        Globals.ThisAddIn.ProcessingUpdate("Update Any Templates with the clause");
                        RefreshAllTaskPanesWithClause(propa[1], doc.WordOpenXML);
                        doc.Activate();

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "Contract" || propa[0] == "UAContract")
                    {
                        //Save the doc and the data
                        GetTaskPaneControlContract().SaveContract(false,true);

                        //Cancel the save
                        SaveAsUI = false;
                        Cancel = true;
                    }

                    if (propa[0] == "Compare")
                    {
//.........这里部分代码省略.........
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon01,代码行数:101,代码来源:ThisAddIn.cs


注:本文中的Microsoft.Office.Interop.Word.SaveAs2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。