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


C# Document.SaveAs方法代码示例

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


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

示例1: LinkInFile

        /// <summary>
        /// Link in the new created document to parent document.
        /// </summary>
        /// <param name="baseFileName">The full path to the IFC file.</param>
        /// <param name="ifcDocument">The newly imported IFC file document.</param>
        /// <param name="originalDocument">The document to contain the IFC link.</param>
        /// <param name="useExistingType">True if the RevitLinkType already exists.</param>
        /// <param name="doSave">True if we should save the document.  This should only be false if we are reusing a cached document.</param>
        public static void LinkInFile(string baseFileName, Document ifcDocument, Document originalDocument, bool useExistingType, bool doSave)
        {
            bool saveSucceded = true;
            string fileName = GenerateRevitFileName(baseFileName);
            
            if (doSave)
            {
                SaveAsOptions saveAsOptions = new SaveAsOptions();
                saveAsOptions.OverwriteExistingFile = true;
                
                try
                {
                    ifcDocument.SaveAs(fileName, saveAsOptions);
                }
                catch (Exception ex)
                {
                    // We still want to close the document to prevent having a corrupt model in memory.
                    IFCImportFile.TheLog.LogError(-1, ex.Message, false);
                    saveSucceded = false;
                }
            }

            if (!ifcDocument.IsLinked)
                ifcDocument.Close(false);

            if (!saveSucceded)
                return;

            bool doReloadFrom = useExistingType && !Importer.TheOptions.CreateLinkInstanceOnly;

            ElementId revitLinkTypeId = ElementId.InvalidElementId;
            if (Importer.TheOptions.RevitLinkFileName != null)
            {
                FilePath originalRevitFilePath = new FilePath(Importer.TheOptions.RevitLinkFileName);
                revitLinkTypeId = RevitLinkType.GetTopLevelLink(originalDocument, originalRevitFilePath);
            }

            if (!doReloadFrom)
            {
                Transaction linkTransaction = new Transaction(originalDocument);
                linkTransaction.Start(Resources.IFCLinkFile);

                try
                {
                    if (revitLinkTypeId == ElementId.InvalidElementId)
                    {
                        RevitLinkOptions options = new RevitLinkOptions(true);
                        RevitLinkLoadResult loadResult = RevitLinkType.CreateFromIFC(originalDocument, baseFileName, fileName, false, options);
                        if ((loadResult != null) && (loadResult.ElementId != ElementId.InvalidElementId))
                            revitLinkTypeId = loadResult.ElementId;
                    }

                    if (revitLinkTypeId != ElementId.InvalidElementId)
                        RevitLinkInstance.Create(originalDocument, revitLinkTypeId);

                    Importer.PostDelayedLinkErrors(originalDocument);
                    linkTransaction.Commit();
                }
                catch (Exception ex)
                {
                    linkTransaction.RollBack();
                    throw ex;
                }
            }
            else // reload from
            {
                // For the reload from case, we expect the transaction to have been created in the UI.
                if (revitLinkTypeId != ElementId.InvalidElementId)
                {
                    RevitLinkType existingRevitLinkType = originalDocument.GetElement(revitLinkTypeId) as RevitLinkType;
                    if (existingRevitLinkType != null)
                        existingRevitLinkType.UpdateFromIFC(originalDocument, baseFileName, fileName, false);
                }
            }
        }
开发者ID:whztt07,项目名称:RevitIFC,代码行数:83,代码来源:IFCImportFile.cs

示例2: CreateDocument

        public void CreateDocument(string Path)
        {
            _DocApp = new Application();
            //_DocApp.Visible = false;

            _doc = _DocApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

            foreach (Section section in _doc.Sections)
            {
                Range headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
                headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                headerRange.Font.ColorIndex = WdColorIndex.wdBlue;
                headerRange.Font.Size = 10;
                headerRange.Text = "TEST";
            }
            foreach (Section wordSection in _doc.Sections)
            {
                Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed;
                footerRange.Font.Size = 10;
                footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                footerRange.Text = "Footer TEST";
            }

            _doc.Content.SetRange(0, 0);
            _doc.Content.Text = "Text TEST";

            object filename = Path; //@"c:\temp1.docx";

            Object fileFormat = WdSaveFormat.wdFormatDocument;
            Object lockComments = false;
            Object password = "";
            Object addToRecentFiles = false;
            Object writePassword = "";
            Object readOnlyRecommended = false;
            Object embedTrueTypeFonts = false;
            Object saveNativePictureFormat = false;
            Object saveFormsData = false;
            Object saveAsAOCELetter = Type.Missing;
            Object encoding = Type.Missing;
            Object insertLineBreaks = Type.Missing;
            Object allowSubstitutions = Type.Missing;
            Object lineEnding = Type.Missing;
            Object addBiDiMarks = Type.Missing;

            _doc.SaveAs(ref filename,
             ref fileFormat, ref lockComments,
             ref password, ref addToRecentFiles, ref writePassword,
             ref readOnlyRecommended, ref embedTrueTypeFonts,
             ref saveNativePictureFormat, ref saveFormsData,
             ref saveAsAOCELetter, ref encoding, ref insertLineBreaks,
             ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);

            //_doc.SaveAs2(ref filename);
            _doc.Close(ref missing, ref missing, ref missing);
            _doc = null;
            _DocApp.Quit(ref missing, ref missing, ref missing);
            _DocApp = null;
            //MessageBox.Show("Document created successfully !");
        }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:61,代码来源:Class1.cs

示例3: CreateCharList

        protected void CreateCharList(int index)
        {
            Object oMissing = System.Reflection.Missing.Value;
            Object oTemplatePath = Directory.GetCurrentDirectory()+"\\resources\\HeroTemplate.dotx";

            Application wordApp = new Application();
            Document wordDoc = new Document();

            wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

            foreach (Field myMergeField in wordDoc.Fields)
            {

                Range rngFieldCode = myMergeField.Code;
                String fieldText = rngFieldCode.Text;

                if (fieldText.StartsWith(" MERGEFIELD"))
                {

                    Int32 endMerge = fieldText.IndexOf("\\");
                    Int32 fieldNameLength = fieldText.Length - endMerge;
                    String fieldName = fieldText.Substring(11, endMerge - 11);

                    fieldName = fieldName.Trim();
                    string value = GetValue(index, fieldName);
                    if (!string.IsNullOrEmpty(value))
                    {
                        myMergeField.Select();
                        wordApp.Selection.TypeText(value);
                    }
                }
            }
            if (!Directory.Exists(Directory.GetCurrentDirectory() + "\\" + GameName))
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\" + GameName);
            wordDoc.SaveAs(Directory.GetCurrentDirectory() + "\\" + GameName + "\\" + Heroes[index].Name+".doc");
        }
开发者ID:dazzgt,项目名称:DnDMasterTool,代码行数:36,代码来源:MasterToolViewModel.cs

示例4: Merge


//.........这里部分代码省略.........
                if (nPages % 2 == 1)
                {
                    Word.Paragraph paragraph = myWordDoc.Content.Paragraphs.Add(ref oMissing);
                    paragraph.Range.InsertParagraphBefore();
                    paragraph.Range.Text = string.Empty;
                    paragraph.Range.InsertBreak(ref oPageBreak);
                    paragraph.Range.InsertParagraphAfter();
                }
            }

            Log("Adding pages");

            if (extraPages != null)
            {
                for(int i=0; i<extraPages.Length; i++)
                {
                    string text = Environment.NewLine + Environment.NewLine +
                                  Environment.NewLine + Environment.NewLine +
                                  Environment.NewLine + Environment.NewLine + extraPages[i];

                    Word.Paragraph paragraph;

                    //if (oSourceTemplatePath != null || i > 0)  // if not blank doc OR not first extra page -- add page break first
                    //{
                    //    paragraph = myWordDoc.Content.Paragraphs.Add(ref oMissing);
                    //    paragraph.Range.InsertParagraphBefore();
                    //    paragraph.Range.Text = string.Empty;
                    //    paragraph.Range.InsertBreak(ref oPageBreak);
                    //    paragraph.Range.InsertParagraphAfter();
                    //}

                    //paragraph = myWordDoc.Content.Paragraphs.Add(ref oMissing);
                    //paragraph.Range.InsertParagraphBefore();
                    //paragraph.Range.Text = text;
                    //paragraph.Range.InsertParagraphAfter();

                    paragraph = myWordDoc.Content.Paragraphs.Add(ref oMissing);
                    if ((oSourceTemplatePath != null && addExtraPagesAtEnd) || i > 0)  // if not blank doc OR not first extra page -- add page break first
                        paragraph.Range.InsertBreak(ref oPageBreak);
                    paragraph.Range.InsertBefore(text);
                }
            }

            // but put it at the end of all notes
            if (isDoubleSidedPrinting) // make sure so far, even nbr of pages
            {
                int nPages = myWordDoc.ComputeStatistics(Word.WdStatistic.wdStatisticPages, ref oMissing);
                if (nPages % 2 == 1)
                {
                    Word.Paragraph paragraph = myWordDoc.Content.Paragraphs.Add(ref oMissing);
                    paragraph.Range.InsertParagraphBefore();
                    paragraph.Range.Text = string.Empty;
                    paragraph.Range.InsertBreak(ref oPageBreak);
                    paragraph.Range.InsertParagraphAfter();
                }
            }

            object fileFormat = System.IO.Path.GetExtension(oOutputDocPath.ToString()).ToUpper() == ".PDF" ? Word.WdSaveFormat.wdFormatPDF : oMissing;
            myWordDoc.SaveAs(
                     ref oOutputDocPath,
                     ref fileFormat,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing,
                     ref oMissing);

            //CLOSE THE FINAL DOC
            myWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(myWordDoc);
            myWordDoc = null;

            Log("Merge complete");

            return true;
        }
        catch (System.Exception ex)
        {
            errorString = ex.ToString(); //.Message;
        }
        finally
        {
            //RELEASE WORD ITSELF
            try{ myWordApp.Quit(ref oFalse, ref oMissing, ref oMissing);             } catch (Exception) { }
            try{ System.Runtime.InteropServices.Marshal.ReleaseComObject(myWordApp); } catch (Exception) { }
            try{ myWordApp = null;                                                   } catch (Exception) { }
            GC.Collect();
        }

        return false;
    }
开发者ID:nblaurenciana-md,项目名称:Websites,代码行数:101,代码来源:WordMailMerger.cs

示例5: tab

        public void tab(Application appWord, Document doc)
        {
            //Microsoft.Office.Interop.Word.Application appWord = null;//应用程序

            // doc = null;//文档

            appWord = new Microsoft.Office.Interop.Word.Application();

            appWord.Visible = false;

            object objTrue = true;

            object objFalse = false;

            object objTemplate = Server.MapPath("person.dot");//模板路径

            object objDocType = WdDocumentType.wdTypeDocument;

            doc = (Document)appWord.Documents.Add(ref objTemplate, ref objFalse, ref objDocType, ref objTrue);

            //第一步生成word文档
            //定义书签变量

            object obDD_Name = "bm_Name";//

            object obDD_Sex = "bm_Sex";//

            object obDD_Birthday = "bm_Birthday"; //

            object obpic = "pic";

            object obtable = "obtable";

            object Nothing = System.Reflection.Missing.Value;

            InlineShape shape = appWord.Selection.InlineShapes.AddPicture(Server.MapPath("../ReportManage/IMG_1405.JPG"), ref Nothing, ref Nothing, ref Nothing);

            //第二步读取数据,填充数据集

            System.Data.DataTable dt = new DataTable();

            dt.Columns.Add("p_Name");

            dt.Columns.Add("p_Sex");

            dt.Columns.Add("p_Birthday");

            DataRow dr = dt.NewRow();

            dr["p_Name"] = "张三";

            dr["p_Sex"] = "男";

            dr["p_Birthday"] = "1980-01-01";

            dt.Rows.Add(dr);

            //第三步
            //给书签赋值

            doc.Bookmarks.get_Item(ref obDD_Name).Range.Text = dt.Rows[0]["p_Name"].ToString(); //

            doc.Bookmarks.get_Item(ref obDD_Sex).Range.Text = dt.Rows[0]["p_Sex"].ToString();//

            doc.Bookmarks.get_Item(ref obDD_Birthday).Range.Text =

            dt.Rows[0]["p_Birthday"].ToString();//

            doc.Bookmarks.get_Item(ref obpic).Range.InlineShapes.AddPicture(Server.MapPath("../ReportManage/IMG_1405.JPG"), ref Nothing, ref Nothing, ref Nothing);

            //文档中插入表格

            doc.Bookmarks.get_Item(ref obtable).Range.Tables.Add(doc.Bookmarks.get_Item(ref obtable).Range, 12, 3, ref Nothing, ref Nothing);

            Microsoft.Office.Interop.Word.Table newTable = doc.Tables.Add(doc.Bookmarks.get_Item(ref obtable).Range, 12, 3, ref Nothing, ref Nothing);

            newTable.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;

            newTable.Borders.InsideLineStyle = WdLineStyle.wdLineStyleSingle;

            //给文档的最后一行再添加内容
            doc.Paragraphs.Last.Range.Text = "";

            //第四步生成word
            object filename = @"C:ss.doc";

            object miss = System.Reflection.Missing.Value;

            doc.SaveAs(ref filename, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

            object missingValue = Type.Missing;

            object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;

            doc.Close(ref doNotSaveChanges, ref missingValue, ref missingValue);

            appWord.Application.Quit(ref miss, ref miss, ref miss);

            doc = null;

//.........这里部分代码省略.........
开发者ID:eseawind,项目名称:YCJN,代码行数:101,代码来源:ConsumeReport.aspx.cs

示例6: Main

        static void Main(string[] args)
        {
            //OBJECT OF MISSING "NULL VALUE"

            Object oMissing = System.Reflection.Missing.Value;

            Object oTemplatePath = "E:/TemplateOfDatacenter.dotx";


            Application wordApp = new Application();
            Document wordDoc = new Document();

            wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

            foreach (Field myMergeField in wordDoc.Fields)
            {


                Range rngFieldCode = myMergeField.Code;

                String fieldText = rngFieldCode.Text;



                // ONLY GETTING THE MAILMERGE FIELDS

                if (fieldText.StartsWith(" MERGEFIELD"))
                {

                    // THE TEXT COMES IN THE FORMAT OF

                    // MERGEFIELD  MyFieldName  \\* MERGEFORMAT

                    // THIS HAS TO BE EDITED TO GET ONLY THE FIELDNAME "MyFieldName"

                    Int32 endMerge = fieldText.IndexOf("\\");

                    Int32 fieldNameLength = fieldText.Length - endMerge;

                    String fieldName = fieldText.Substring(11, endMerge - 11);

                    // GIVES THE FIELDNAMES AS THE USER HAD ENTERED IN .dot FILE

                    fieldName = fieldName.Trim();

                    // **** FIELD REPLACEMENT IMPLEMENTATION GOES HERE ****//

                    // THE PROGRAMMER CAN HAVE HIS OWN IMPLEMENTATIONS HERE

                    if (fieldName == "PartA")
                    {

                        myMergeField.Select();

                        wordApp.Selection.TypeText("Nguyễn Văn Giàu");

                    }
                    if (fieldName == "Representative")
                    {
                        myMergeField.Select();
                        wordApp.Selection.TypeText("giaunv");
                    }

                }

            }
            wordDoc.SaveAs("myfile.doc");
            wordApp.Documents.Open("myFile.doc");
            wordApp.Application.Quit();
        
    }
开发者ID:haltt051093,项目名称:IMS-datacenter,代码行数:71,代码来源:Program.cs

示例7: ConverteerBestand

        /// <summary>
        /// Methode die het word document opslaat als PDF bestand.
        /// </summary>
        /// <param name="excelBestand">Bestand om te zetten</param>
        public void ConverteerBestand(FileInfo wordBestand)
        {
            //Volledig pad ophalen en opslaan als object voor word.Documents.Open methode
            Object filename = (Object)wordBestand.FullName;

            //Optionele argumenten opvullen met leeg object
            doc = word.Documents.Open(ref filename, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            doc.Activate();

            object outputFileName = String.Format("{0}.pdf", wordBestand.FullName.Substring(0, wordBestand.FullName.LastIndexOf('.')));
            object fileFormat = WdSaveFormat.wdFormatPDF;

            //Document opslaanals PDF
            doc.SaveAs(ref outputFileName,
                ref fileFormat, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //Document sluiten maar word nog niet.
            //Doc moet naar _Document geconverteerd worden zodat de Close methode opgeroepen kan worden.
            if (doc != null)
            {
                object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
                ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
                doc = null;
            }
        }
开发者ID:EusebiusVD,项目名称:Stage,代码行数:35,代码来源:WordNaarPDF.cs


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