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


C# WordprocessingDocument类代码示例

本文整理汇总了C#中WordprocessingDocument的典型用法代码示例。如果您正苦于以下问题:C# WordprocessingDocument类的具体用法?C# WordprocessingDocument怎么用?C# WordprocessingDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CreateParts

        // Adds child parts and generates content of the specified part.
        private void CreateParts(WordprocessingDocument document)
        {
            ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
            GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);

            MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
            GenerateMainDocumentPart1Content(mainDocumentPart1);

            StylesWithEffectsPart stylesWithEffectsPart1 = mainDocumentPart1.AddNewPart<StylesWithEffectsPart>("rId3");
            GenerateStylesWithEffectsPart1Content(stylesWithEffectsPart1);

            ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId7");
            GenerateThemePart1Content(themePart1);

            StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId2");
            GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);

            CustomXmlPart customXmlPart1 = mainDocumentPart1.AddNewPart<CustomXmlPart>("application/xml", "rId1");
            GenerateCustomXmlPart1Content(customXmlPart1);

            CustomXmlPropertiesPart customXmlPropertiesPart1 = customXmlPart1.AddNewPart<CustomXmlPropertiesPart>("rId1");
            GenerateCustomXmlPropertiesPart1Content(customXmlPropertiesPart1);

            FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId6");
            GenerateFontTablePart1Content(fontTablePart1);

            WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId5");
            GenerateWebSettingsPart1Content(webSettingsPart1);

            DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId4");
            GenerateDocumentSettingsPart1Content(documentSettingsPart1);

            documentSettingsPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new System.Uri("file:///D:\\Downloads\\FamilyMergeDoc%20(2).dotx", System.UriKind.Absolute), "rId1");
        }
开发者ID:stevesloka,项目名称:bvcms,代码行数:35,代码来源:FamilyDir.cs

示例2: GetText

        public string GetText(string docFilePath)
        {
            try
            {
                this.package = WordprocessingDocument.Open(docFilePath, true);

                StringBuilder sb = new StringBuilder();
                OpenXmlElement element = package.MainDocumentPart.Document.Body;
                if (element == null)
                {
                    return string.Empty;
                }

                sb.Append(GetPlainText(element));
                return sb.ToString(); 
            }
            catch (Exception e)
            {

                throw;
            }
            finally
            {
                GC.Collect();
            }
        }
开发者ID:zeferreira,项目名称:eDoc,代码行数:26,代码来源:DocParserDocxOpenXML.cs

示例3: ReplaceBookmark

        public void ReplaceBookmark(WordprocessingDocument package, string bookmark, string content)
        {
            IDictionary<String, BookmarkStart> bookmarkMap = new Dictionary<String, BookmarkStart>();

            foreach (BookmarkStart bookmarkStart in package.MainDocumentPart.RootElement.Descendants<BookmarkStart>()) {
                bookmarkMap[bookmarkStart.Name] = bookmarkStart;
            }

            foreach (BookmarkStart bookmarkStart in bookmarkMap.Values) {

                if (bookmarkStart.Name == bookmark) {

                    Run bookmarkText = bookmarkStart.NextSibling<Run>();
                    if (bookmarkText != null) {
                        bookmarkText.GetFirstChild<Text>().Text = content;
                    }
                    else {
                        var textElement = new Text(content);
                        var runElement = new Run(textElement);

                        bookmarkStart.InsertAfterSelf(runElement);
                    }
                }
            }
        }
开发者ID:FerHenrique,项目名称:Owl,代码行数:25,代码来源:BookmarkReplacer.cs

示例4: CreateParts

        // Adds child parts and generates content of the specified part.
        private void CreateParts(WordprocessingDocument document)
        {
            ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
            GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);

            MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
            GenerateMainDocumentPart1Content(mainDocumentPart1);

            DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId3");
            GenerateDocumentSettingsPart1Content(documentSettingsPart1);

            StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId2");
            GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);

            CustomXmlPart customXmlPart1 = mainDocumentPart1.AddNewPart<CustomXmlPart>("application/xml", "rId1");
            GenerateCustomXmlPart1Content(customXmlPart1);

            CustomXmlPropertiesPart customXmlPropertiesPart1 = customXmlPart1.AddNewPart<CustomXmlPropertiesPart>("rId1");
            GenerateCustomXmlPropertiesPart1Content(customXmlPropertiesPart1);

            ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId6");
            GenerateThemePart1Content(themePart1);

            FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId5");
            GenerateFontTablePart1Content(fontTablePart1);

            WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId4");
            GenerateWebSettingsPart1Content(webSettingsPart1);

            SetPackageProperties(document);
        }
开发者ID:CGHill,项目名称:Hard-To-Find,代码行数:32,代码来源:InvoiceCreator.cs

示例5: CreateProcessor

        public static GeneralDataProcessor CreateProcessor(WordprocessingDocument document, DCTDataProperty property)
        {
            if (property is DCTSimpleProperty)
                return new SimplePropertyProcessor(document, (DCTSimpleProperty)property);

            return new ComplexPropertyProcessor(document, (DCTComplexProperty)property);
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:7,代码来源:GeneralDataProcessor.cs

示例6: CreateParts

        // Adds child parts and generates content of the specified part.
        private void CreateParts(WordprocessingDocument document)
        {
            ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
            GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);

            MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
            GenerateMainDocumentPart1Content(mainDocumentPart1);

            FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId8");
            GenerateFontTablePart1Content(fontTablePart1);

            WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId3");
            GenerateWebSettingsPart1Content(webSettingsPart1);

            DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId2");
            GenerateDocumentSettingsPart1Content(documentSettingsPart1);

            StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId1");
            GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);

            ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId9");
            GenerateThemePart1Content(themePart1);

            mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("mailto:[email protected]", System.UriKind.Absolute), true, "rId7");
            mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("http://www.shivam.com", System.UriKind.Absolute), true, "rId6");
            mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("mailto:[email protected]", System.UriKind.Absolute), true, "rId5");
            mainDocumentPart1.AddHyperlinkRelationship(new System.Uri("http://www.google.com", System.UriKind.Absolute), true, "rId4");
            SetPackageProperties(document);
        }
开发者ID:vijaypaliwal,项目名称:locum,代码行数:30,代码来源:Generateinvoice.cs

示例7: AddFontTablePartToPackage

 public FontTablePart AddFontTablePartToPackage(WordprocessingDocument doc)
 {
     var part = doc.MainDocumentPart.AddNewPart<FontTablePart>();
     var root = new Fonts();
     root.Save(part);
     return part;
 }
开发者ID:Jaykul,项目名称:pickles,代码行数:7,代码来源:WordFontApplicator.cs

示例8: WordprocessingDocumentToStream

        private static Stream WordprocessingDocumentToStream(WordprocessingDocument wordDoc)
        {
            MemoryStream mem = new MemoryStream();

            using (var resultDoc = WordprocessingDocument.Create(mem, wordDoc.DocumentType))
            {

                // copy parts from source document to new document
                foreach (var part in wordDoc.Parts)
                {
                    OpenXmlPart targetPart = resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId); // that's recursive :-)
                }

                resultDoc.Package.Flush();
            }
            //resultDoc.Package.Close(); // must do this (or using), or the zip won't get created properly

            mem.Position = 0;

            return mem;

            //    byte[] bytes = new byte[mem.Length];
            //    mem.Read(bytes, 0, (int)mem.Length);
            //    mem.Close();

            //    //FileStream file = new FileStream(@"C:\Users\jharrop\Documents\tmp-test-docx\outs.docx", FileMode.Create, System.IO.FileAccess.Write);
            //    //byte[] bytes = new byte[mem.Length];
            //    //mem.Read(bytes, 0, (int)mem.Length);
            //    //file.Write(bytes, 0, bytes.Length);
            //    //file.Close();
            //    //mem.Close();

            //return bytes;

        }
开发者ID:Abhishek-add,项目名称:docx4j.NET,代码行数:35,代码来源:WordprocessingMLPackageFactory.cs

示例9: CreateParts

		// Adds child parts and generates content of the specified part.
		private void CreateParts(WordprocessingDocument document)
		{
			ExtendedFilePropertiesPart extendedFilePropertiesPart1 = document.AddNewPart<ExtendedFilePropertiesPart>("rId3");
			GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart1);

			MainDocumentPart mainDocumentPart1 = document.AddMainDocumentPart();
			GenerateMainDocumentPart1Content(mainDocumentPart1);

			DocumentSettingsPart documentSettingsPart1 = mainDocumentPart1.AddNewPart<DocumentSettingsPart>("rId3");
			GenerateDocumentSettingsPart1Content(documentSettingsPart1);

			StylesWithEffectsPart stylesWithEffectsPart1 = mainDocumentPart1.AddNewPart<StylesWithEffectsPart>("rId2");
			GenerateStylesWithEffectsPart1Content(stylesWithEffectsPart1);

			StyleDefinitionsPart styleDefinitionsPart1 = mainDocumentPart1.AddNewPart<StyleDefinitionsPart>("rId1");
			GenerateStyleDefinitionsPart1Content(styleDefinitionsPart1);

			ThemePart themePart1 = mainDocumentPart1.AddNewPart<ThemePart>("rId6");
			GenerateThemePart1Content(themePart1);

			FontTablePart fontTablePart1 = mainDocumentPart1.AddNewPart<FontTablePart>("rId5");
			GenerateFontTablePart1Content(fontTablePart1);

			WebSettingsPart webSettingsPart1 = mainDocumentPart1.AddNewPart<WebSettingsPart>("rId4");
			GenerateWebSettingsPart1Content(webSettingsPart1);

		}
开发者ID:stevesloka,项目名称:bvcms,代码行数:28,代码来源:EmployerAddress.cs

示例10: SimplifyMarkup

 public static void SimplifyMarkup(WordprocessingDocument doc,
     SimplifyMarkupSettings settings)
 {
     SimplifyMarkupForPart(doc.MainDocumentPart, settings);
     SimplifyMarkupForPart(doc.MainDocumentPart.StyleDefinitionsPart, settings);
     SimplifyMarkupForPart(doc.MainDocumentPart.StylesWithEffectsPart, settings);
 }
开发者ID:mvlasenko,项目名称:TridionDesktopTools,代码行数:7,代码来源:MarkupSimplifier.cs

示例11: GenerateWordDocument

        public void GenerateWordDocument(string docName, SessionData sessionObjects, AdditionalData additionalObjects)
        {
            _sessionObjects = sessionObjects;
            _additionalObjects = additionalObjects;
            //var openS = new OpenSettings();
            //openS.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(
            //    MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2007);
            //using (_wordDocument = WordprocessingDocument.Open(docName, true, openS))
            using (_wordDocument = WordprocessingDocument.Create(docName, WordprocessingDocumentType.Document))
            {
                InitilizeDocument();

                GenerateTitlePage();
                GeneratePageTwo();
                GenerateChapterOne();
                GenerateChapterTwo();
                GenerateChapterThree();
                GenerateChapterFour();
                GenerateChapterFive();
                GenerateChapterSix();
                GenerateChapterSeven();
                GenerateChapterEight();
                GenerateChapterNine();
                GenerateChapterTen();
                var numberingDefinitionsPart = _mainPart.AddNewPart<NumberingDefinitionsPart>();
                numberingDefinitionsPart.Numbering = _numbering;
            }
        }
开发者ID:silmarion,项目名称:WPDHelper,代码行数:28,代码来源:DocBuilder.cs

示例12: WordDocumentImageManipulator

        public WordDocumentImageManipulator(WordprocessingDocument doc)
        {

            // Open the document as editable.
            Document = doc;

        }
开发者ID:oghenez,项目名称:trade-software,代码行数:7,代码来源:WordDocumentImageManipulator.cs

示例13: DocxParser

        public DocxParser(string fileName)
        {
            path = Path.GetTempPath() + Path.DirectorySeparatorChar + "tmp-" + DateTime.Now.Ticks.ToString();
            File.Copy(fileName, path);

            doc = WordprocessingDocument.Open(path, true);

            parsedFile = new ContentFile()
            {
                contentRaw = doc.MainDocumentPart.Document.InnerXml,
                contentText = ParseFileContent(XElement.Parse(doc.MainDocumentPart.Document.InnerXml))
            };

            SetMetadata(MetadataType.Author, doc.PackageProperties.Creator);
            SetMetadata(MetadataType.Description, doc.PackageProperties.Description);
            SetMetadata(MetadataType.Language, doc.PackageProperties.Language);
            SetMetadata(MetadataType.Subject, doc.PackageProperties.Subject);
            SetMetadata(MetadataType.Title, doc.PackageProperties.Title);
            SetMetadata(MetadataType.Type, doc.PackageProperties.ContentType);

            if (doc.PackageProperties.Created.HasValue)
                SetMetadata(MetadataType.PublishDate, doc.PackageProperties.Created.Value.ToString());

            LoadAllMetadata();
        }
开发者ID:sashaMilka,项目名称:MultiReader,代码行数:25,代码来源:DocxParser.cs

示例14: RetrieveListItem

 public static string RetrieveListItem(WordprocessingDocument wordDoc,
     XElement paragraph, string bulletReplacementString)
 {
     string pt = paragraph.Elements(W.r).Elements(W.t).Select(e => e.Value)
         .StringConcatenate();
     NumberingDefinitionsPart numberingDefinitionsPart =
         wordDoc.MainDocumentPart.NumberingDefinitionsPart;
     if (numberingDefinitionsPart == null)
         return null;
     StyleDefinitionsPart styleDefinitionsPart = wordDoc.MainDocumentPart
         .StyleDefinitionsPart;
     if (styleDefinitionsPart == null)
         return null;
     XDocument numbering = numberingDefinitionsPart.GetXDocument();
     XDocument styles = styleDefinitionsPart.GetXDocument();
     ListItemInfo listItemInfo = GetListItemInfo(numbering, styles, paragraph);
     if (listItemInfo.IsListItem)
     {
         string lvlText = (string)listItemInfo.Lvl.Elements(W.lvlText)
             .Attributes(W.val).FirstOrDefault();
         int[] levelNumbers = GetLevelNumbers(numbering, styles, paragraph);
         paragraph.AddAnnotation(new LevelNumbers()
         {
             LevelNumbersArray = levelNumbers
         });
         string listItem = FormatListItem(listItemInfo.Lvl, levelNumbers, lvlText,
             bulletReplacementString);
         return listItem;
     }
     return null;
 }
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:31,代码来源:ListItemRetriever.cs

示例15: CompareDocuments

        // todo
        // we want overload for this that takes WmlDocument, or whatever new class is.
        // also want ability to specify multiple options - a settings object - compare headers, footers, etc.
        //
        // Returns true if docs are the same, otherwise false.
        public static bool CompareDocuments(WordprocessingDocument doc1, WordprocessingDocument doc2)
        {
            XDocument doc1XDoc = doc1.MainDocumentPart.GetXDocument();
            XDocument doc2XDoc = doc2.MainDocumentPart.GetXDocument();
            if (CompareOpenXmlElements(doc1XDoc.Root, doc2XDoc.Root) == false)
                return false;

            // for the current use of this class, only need to compare the main document parts.
            #if false
            if (doc1.MainDocumentPart.HeaderParts.Count() != doc2.MainDocumentPart.HeaderParts.Count())
                return false;
            foreach (var pair in doc1
                .MainDocumentPart
                .HeaderParts
                .Zip(doc2.MainDocumentPart.HeaderParts, (d1, d2) =>
                    new
                    {
                        Doc1Header = d1,
                        Doc2Header = d2,
                    }))
            {
                if (CompareOpenXmlElements(pair.Doc1Header.GetXDocument().Root,
                    pair.Doc2Header.GetXDocument().Root) == false)
                    return false;
            }
            if (doc1.MainDocumentPart.FooterParts.Count() != doc2.MainDocumentPart.FooterParts.Count())
                return false;
            foreach (var pair in doc1
                .MainDocumentPart
                .FooterParts
                .Zip(doc2.MainDocumentPart.FooterParts, (d1, d2) =>
                    new
                    {
                        Doc1Footer = d1,
                        Doc2Footer = d2,
                    }))
            {
                if (CompareOpenXmlElements(pair.Doc1Footer.GetXDocument().Root,
                    pair.Doc2Footer.GetXDocument().Root) == false)
                    return false;
            }
            if ((doc1.MainDocumentPart.FootnotesPart == null) != (doc2.MainDocumentPart.FootnotesPart == null))
                return false;
            if (doc1.MainDocumentPart.FootnotesPart != null)
            {
                if (CompareOpenXmlElements(doc1.MainDocumentPart.FootnotesPart.GetXDocument().Root,
                    doc2.MainDocumentPart.FootnotesPart.GetXDocument().Root) == false)
                    return false;
            }
            if ((doc1.MainDocumentPart.EndnotesPart == null) != (doc2.MainDocumentPart.EndnotesPart == null))
                return false;
            if (doc1.MainDocumentPart.EndnotesPart != null)
            {
                if (CompareOpenXmlElements(doc1.MainDocumentPart.EndnotesPart.GetXDocument().Root,
                    doc2.MainDocumentPart.EndnotesPart.GetXDocument().Root) == false)
                    return false;
            }
            #endif
            return true;
        }
开发者ID:jecabana,项目名称:Portal-Vanity-Daniel-en-stand-by,代码行数:65,代码来源:DocumentComparer.cs


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