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


C# Document.Save方法代码示例

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


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

示例1: ChangeTOCTabStops

        public void ChangeTOCTabStops()
        {
            //ExStart
            //ExFor:TabStop
            //ExFor:ParagraphFormat.TabStops
            //ExFor:Style.StyleIdentifier
            //ExFor:TabStopCollection.RemoveByPosition
            //ExFor:TabStop.Alignment
            //ExFor:TabStop.Position
            //ExFor:TabStop.Leader
            //ExId:ChangeTOCTabStops
            //ExSummary:Shows how to modify the position of the right tab stop in TOC related paragraphs.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc");

            // Iterate through all paragraphs in the document
            foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
            {
                // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9.
                if (para.ParagraphFormat.Style.StyleIdentifier >= StyleIdentifier.Toc1 && para.ParagraphFormat.Style.StyleIdentifier <= StyleIdentifier.Toc9)
                {
                    // Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
                    TabStop tab = para.ParagraphFormat.TabStops[0];
                    // Remove the old tab from the collection.
                    para.ParagraphFormat.TabStops.RemoveByPosition(tab.Position);
                    // Insert a new tab using the same properties but at a modified position.
                    // We could also change the separators used (dots) by passing a different Leader type
                    para.ParagraphFormat.TabStops.Add(tab.Position - 50, tab.Alignment, tab.Leader);
                }
            }

            doc.Save(ExDir + "Document.TableOfContentsTabStops Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:33,代码来源:ExStyles.cs

示例2: ConvertWordToImage

        /// <summary>
        /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法:
        /// ConvertPDF2Image("F:\\PdfFile.doc", "F:\\", "ImageFile", 1, 20, ImageFormat.Png, 256);
        /// </summary>
        /// <param name="pdfInputPath">Word文件路径</param>
        /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
        /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
        /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
        /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
        /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
        public static void ConvertWordToImage(string wordInputPath, string imageOutputPath,
            string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
        {
            try
            {
                // open word file
                Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

                // validate parameter
                if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
                if (imageOutputPath.Trim().Length == 0) { imageOutputPath = Path.GetDirectoryName(wordInputPath); }
                if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
                if (imageName.Trim().Length == 0) { imageName = Path.GetFileNameWithoutExtension(wordInputPath); }
                if (startPageNum <= 0) { startPageNum = 1; }
                if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
                if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
                if (imageFormat == null) { imageFormat = ImageFormat.Png; }
                if (resolution <= 0) { resolution = 128; }

                ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat));
                imageSaveOptions.Resolution = resolution;

                // start to convert each page
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    imageSaveOptions.PageIndex = i - 1;
                    doc.Save(Path.Combine(imageOutputPath, imageName) + "_" + i.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:alqadasifathi,项目名称:OfficeTools.Pdf2Image.Word2Image,代码行数:45,代码来源:Program.cs

示例3: InsertNewColumnIntoTable

        public void InsertNewColumnIntoTable()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            //ExStart
            //ExId:InsertNewColumn
            //ExSummary:Shows how to insert a blank column into a table.
            // Get the second column in the table.
            Column column = Column.FromIndex(table, 1);

            // Create a new column to the left of this column.
            // This is the same as using the "Insert Column Before" command in Microsoft Word.
            Column newColumn = column.InsertColumnBefore();

            // Add some text to each of the column cells.
            foreach (Cell cell in newColumn.Cells)
                cell.FirstParagraph.AppendChild(new Run(doc, "Column Text " + newColumn.IndexOf(cell)));
            //ExEnd

            doc.Save(MyDir + "Table.InsertColumn Out.doc");

            Assert.AreEqual(24, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Column Text 0", table.FirstRow.Cells[1].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Column Text 3", table.LastRow.Cells[1].ToString(SaveFormat.Text).Trim());
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:26,代码来源:ExTableColumn.cs

示例4: ReplaceHyperlinks

        public void ReplaceHyperlinks()
        {
            // Specify your document name here.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "ReplaceHyperlinks.doc");

            // Hyperlinks in a Word documents are fields, select all field start nodes so we can find the hyperlinks.
            NodeList fieldStarts = doc.SelectNodes("//FieldStart");
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldHyperlink))
                {
                    // The field is a hyperlink field, use the "facade" class to help to deal with the field.
                    Hyperlink hyperlink = new Hyperlink(fieldStart);

                    // Some hyperlinks can be local (links to bookmarks inside the document), ignore these.
                    if (hyperlink.IsLocal)
                        continue;

                    // The Hyperlink class allows to set the target URL and the display name
                    // of the link easily by setting the properties.
                    hyperlink.Target = NewUrl;
                    hyperlink.Name = NewName;
                }
            }

            doc.Save(ExDir + "ReplaceHyperlinks Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:27,代码来源:ExReplaceHyperlinks.cs

示例5: ConvertRtfToDocx

        //ExStart
        //ExId:MossRtf2Docx
        //ExSummary:Converts an RTF document to OOXML.
        public static void ConvertRtfToDocx(string inFileName, string outFileName)
        {
            // Load an RTF file into Aspose.Words.
            Aspose.Words.Document doc = new Aspose.Words.Document(inFileName);

            // Save the document in the OOXML format.
            doc.Save(outFileName, SaveFormat.Docx);
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:11,代码来源:ExMossRtf2Docx.cs

示例6: ChangeTextToHyperlinks

        public void ChangeTextToHyperlinks()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + @"Range.ChangeTextToHyperlinks.doc");

            // Create regular expression for URL search
            Regex regexUrl = new Regex(@"(?<Protocol>\w+):\/\/(?<Domain>[\w.]+\/?)\S*(?x)");

            // Run replacement, using regular expression and evaluator.
            doc.Range.Replace(regexUrl, new ChangeTextToHyperlinksEvaluator(doc), false);

            // Save updated document.
            doc.Save(MyDir + @"Range.ChangeTextToHyperlinks Out.docx");
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:13,代码来源:ExRange.cs

示例7: MailMergeAlternatingRows

        //ExStart
        //ExId:MailMergeAlternatingRows
        //ExSummary:Demonstrates how to implement custom logic in the MergeField event to apply cell formatting.
        public void MailMergeAlternatingRows()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "MailMerge.AlternatingRows.doc");

            // Add a handler for the MergeField event.
            doc.MailMerge.FieldMergingCallback = new HandleMergeFieldAlternatingRows();

            // Execute mail merge with regions.
            DataTable dataTable = GetSuppliersDataTable();
            doc.MailMerge.ExecuteWithRegions(dataTable);

            doc.Save(ExDir + "MailMerge.AlternatingRows Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:16,代码来源:ExMailMergeEvent.cs

示例8: InsertDocumentAtBookmark

        public void InsertDocumentAtBookmark()
        {
            //ExStart
            //ExId:InsertDocumentAtBookmark
            //ExSummary:Invokes the InsertDocument method shown above to insert a document at a bookmark.
            Aspose.Words.Document mainDoc = new Aspose.Words.Document(ExDir + "InsertDocument1.doc");
            Aspose.Words.Document subDoc = new Aspose.Words.Document(ExDir + "InsertDocument2.doc");

            Aspose.Words.Bookmark bookmark = mainDoc.Range.Bookmarks["insertionPlace"];
            InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc);

            mainDoc.Save(ExDir + "InsertDocumentAtBookmark Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:14,代码来源:ExInsertDocument.cs

示例9: AcceptAllRevisions

        public void AcceptAllRevisions()
        {
            //ExStart
            //ExFor:Document.AcceptAllRevisions
            //ExSummary:Shows how to accept all tracking changes in the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            // Start tracking and make some revisions.
            doc.StartTrackRevisions("Author");
            doc.FirstSection.Body.AppendParagraph("Hello world!");

            // Revisions will now show up as normal text in the output document.
            doc.AcceptAllRevisions();
            doc.Save(MyDir + "Document.AcceptedRevisions.doc");
            //ExEnd
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:16,代码来源:ExDocument.cs

示例10: InsertDocumentAtMailMerge

        //ExStart
        //ExFor:CompositeNode.HasChildNodes
        //ExId:InsertDocumentAtMailMerge
        //ExSummary:Demonstrates how to use the InsertDocument method to insert a document into a merge field during mail merge.
        public void InsertDocumentAtMailMerge()
        {
            // Open the main document.
            Aspose.Words.Document mainDoc = new Aspose.Words.Document(ExDir + "InsertDocument1.doc");

            // Add a handler to MergeField event
            mainDoc.MailMerge.FieldMergingCallback = new InsertDocumentAtMailMergeHandler();

            // The main document has a merge field in it called "Document_1".
            // The corresponding data for this field contains fully qualified path to the document
            // that should be inserted to this field.
            mainDoc.MailMerge.Execute(
                new string[] { "Document_1" },
                new string[] { ExDir + "InsertDocument2.doc" });

            mainDoc.Save(ExDir + "InsertDocumentAtMailMerge Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:21,代码来源:ExInsertDocument.cs

示例11: Process

 /// <summary>
 /// Convert the documents into images
 /// </summary>
 /// <param name="sourcePath"></param>
 /// <param name="targetPath">Path were the documents were generated</param>
 /// <param name="currentPage"></param>
 /// <param name="originalDocumentName"></param>
 /// <returns></returns>
 public int Process(string sourcePath, string targetPath, int currentPage, string originalDocumentName, int qualitySet)
 {
     var qSet = new QualitySet();
     var doc = new Aspose.Words.Document(sourcePath);
     var targetFileName = targetPath.PathSplit();
     var targetFileExt = targetFileName[targetFileName.Length - 1].Split('.');
     var options = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Jpeg)
                   {
                       PageCount = 1,
                       PageIndex = currentPage - 1,
                       Resolution = qSet.Get(qualitySet).Resolution,
                       JpegQuality = qSet.Get(qualitySet).Quality
                   };
     var targetImage = targetPath.Replace("." + targetFileExt[targetFileExt.Length - 1], string.Empty) + currentPage + ConfigurationManager.AppSettings["ImageExtension"];
     doc.Save(targetImage, options);
     return doc.PageCount;
 }
开发者ID:Aranjedeath,项目名称:SpecimenCode,代码行数:25,代码来源:WordDocumentProcessor.cs

示例12: ClearFormattingEx

        public void ClearFormattingEx()
        {
            //ExStart
            //ExFor:Border.ClearFormatting
            //ExSummary:Shows how to remove borders from a paragraph one by one.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.Borders.doc");
            DocumentBuilder builder = new DocumentBuilder(doc);
            BorderCollection borders = builder.ParagraphFormat.Borders;

            foreach (Aspose.Words.Border border in borders)
            {
                border.ClearFormatting();
            }

            builder.CurrentParagraph.Runs[0].Text = "Paragraph with no border";
            doc.Save(MyDir + "Document.NoBorder.doc");
            //ExEnd
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:18,代码来源:ExBorder.cs

示例13: RenameMergeFields

        public void RenameMergeFields()
        {
            // Specify your document name here.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "RenameMergeFields.doc");

            // Select all field start nodes so we can find the merge fields.
            NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))
                {
                    MergeField mergeField = new MergeField(fieldStart);
                    mergeField.Name = mergeField.Name + "_Renamed";
                }
            }

            doc.Save(MyDir + "RenameMergeFields Out.doc");
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:18,代码来源:ExRenameMergeFields.cs

示例14: RemoveColumnFromTable

        public void RemoveColumnFromTable()
        {
            //ExStart
            //ExId:RemoveTableColumn
            //ExSummary:Shows how to remove a column from a table in a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            // Get the third column from the table and remove it.
            Column column = Column.FromIndex(table, 2);
            column.Remove();
            //ExEnd

            doc.Save(MyDir + "Table.RemoveColumn Out.doc");

            Assert.AreEqual(16, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Cell 3 contents", table.Rows[2].Cells[2].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Cell 3 contents", table.LastRow.Cells[2].ToString(SaveFormat.Text).Trim());
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:19,代码来源:ExTableColumn.cs

示例15: Process

 /// <summary>
 /// 
 /// </summary>
 /// <param name="sourcePath"></param>
 /// <param name="targetPath"></param>
 /// <param name="currentPage"></param>
 /// <param name="originalDocumentName"></param>
 /// <returns></returns>
 public int Process(string sourcePath, string targetPath, int currentPage, string originalDocumentName, int qualitySet)
 {
     var msg = MailMessage.Load(sourcePath, MailMessageLoadOptions.DefaultMsg);
     var targetFileName = targetPath.PathSplit();
     var targetFileExt = targetFileName[targetFileName.Length - 1].Split('.');
     var ms = new MemoryStream();
     msg.Save(ms, MailMessageSaveType.MHtmlFromat);
     var loadOptions = new LoadOptions { LoadFormat = (LoadFormat)Aspose.Cells.LoadFormat.MHtml };
     var document = new Aspose.Words.Document(ms, loadOptions);
     var qSet = new QualitySet();
     var options = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Jpeg)
     {
         PageCount = 1,
         PageIndex = currentPage - 1,
         Resolution = qSet.Get(qualitySet).VerticalResolution,
         JpegQuality = qSet.Get(qualitySet).Quality
     };
     var targetImage = targetPath.Replace("." + targetFileExt[targetFileExt.Length - 1], string.Empty) + currentPage + ConfigurationManager.AppSettings["ImageExtension"];
     document.Save(targetImage, options);
     return document.PageCount;
 }
开发者ID:Aranjedeath,项目名称:SpecimenCode,代码行数:29,代码来源:MailMessageDocumentProcessor.cs


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