コード例 #1
1
 public static WmlDocument AddToc(WmlDocument document, string xPath, string switches, string title, int? rightTabPos)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
         {
             AddToc(doc, xPath, switches, title, rightTabPos);
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #2
0
 public static object GetAllComments(WmlDocument doc, CommentFormat format)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
     {
         IEnumerable<XElement> comments = null;
         WordprocessingCommentsPart commentsPart = document.MainDocumentPart.WordprocessingCommentsPart;
         if (commentsPart != null)
         {
             XDocument commentsPartDocument = commentsPart.GetXDocument();
             comments = commentsPartDocument.Element(W.comments).Elements(W.comment);
         }
         if (comments != null)
         {
             XDocument commentsDocument =
                 new XDocument(
                     new XElement(W.comments,
                         new XAttribute(XNamespace.Xmlns + "w", W.w),
                         comments
                     )
                 );
             switch (format)
             {
                 case CommentFormat.PlainText:
                     return commentsDocument.ToString();
                 case CommentFormat.Xml:
                     return commentsDocument;
                 case CommentFormat.Docx:
                     return CreateCommentsDocument(comments);
             }
         }
         return null;
     }
 }
        /// <summary>
        /// Inserts Xml markup representing format attributes inside a specific paragraph or paragraph run
        /// </summary>
        /// <param name="document">Document to insert formatting Xml tags</param>
        /// <param name="xpathInsertionPoint">Paragraph or paragraph run to set format</param>
        /// <param name="content">Formatting tags</param>
        public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, string content)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument xDocument = document.MainDocumentPart.GetXDocument();
                    XmlDocument xmlMainDocument = new XmlDocument();
                    xmlMainDocument.Load(xDocument.CreateReader());

                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

                    XmlNodeList insertionPoints = xmlMainDocument.SelectNodes(xpathInsertionPoint, namespaceManager);

                    if (insertionPoints.Count == 0)
                        throw new ArgumentException("The xpath query did not return a valid location.");

                    foreach (XmlNode insertionPoint in insertionPoints)
                    {
                        XmlNode propertiesElement = insertionPoint.SelectSingleNode(@"w:pPr|w:rPr", namespaceManager);
                        if (insertionPoint.Name == "w:p")
                        {
                            // Checks if the rPr or pPr element exists
                            if (propertiesElement == null)
                            {
                                propertiesElement = xmlMainDocument.CreateElement("w", "pPr", namespaceManager.LookupNamespace("w"));
                                insertionPoint.PrependChild(propertiesElement);
                            }
                        }
                        else if (insertionPoint.Name == "w:r")
                        {
                            // Checks if the rPr or pPr element exists
                            if (propertiesElement == null)
                            {
                                propertiesElement = xmlMainDocument.CreateElement("w", "rPr", namespaceManager.LookupNamespace("w"));
                                insertionPoint.PrependChild(propertiesElement);
                            }
                        }

                        if (propertiesElement != null)
                        {
                            propertiesElement.InnerXml += content;
                        }
                        else
                        {
                            throw new ArgumentException("Specified xpath query result is not a valid location to place a formatting markup");
                        }

                    }
                    XDocument xNewDocument = new XDocument();
                    using (XmlWriter xWriter = xNewDocument.CreateWriter())
                        xmlMainDocument.WriteTo(xWriter);
                    document.MainDocumentPart.PutXDocument(xNewDocument);
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #4
0
 public static XElement ConvertToHtml(WmlDocument doc, HtmlConverterSettings htmlConverterSettings)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             return ConvertToHtml(document, htmlConverterSettings);
         }
     }
 }
コード例 #5
0
 public static string GetBackgroundColor(WmlDocument doc)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
     {
         XDocument mainDocument = document.MainDocumentPart.GetXDocument();
         XElement backgroundElement = mainDocument.Descendants(W.background).FirstOrDefault();
         return (backgroundElement == null) ? string.Empty : backgroundElement.Attribute(W.color).Value;
     }
 }
コード例 #6
0
 public static XElement ConvertToHtml(WmlDocument doc, HtmlConverterSettings htmlConverterSettings, Func<ImageInfo, XElement> imageHandler)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             return ConvertToHtml(document, htmlConverterSettings, imageHandler);
         }
     }
 }
コード例 #7
0
 public static WmlDocument SearchAndReplace(WmlDocument doc, string search, string replace, bool matchCase)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             SearchAndReplace(document, search, replace, matchCase);
         }
         return(streamDoc.GetModifiedWmlDocument());
     }
 }
コード例 #8
0
 private static OpenXmlPowerToolsDocument CreateCommentsDocument(IEnumerable <XElement> contents)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = OpenXmlMemoryStreamDocument.CreateWordprocessingDocument())
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             PowerToolsExtensions.SetContent(document, contents);
         }
         return(streamDoc.GetModifiedDocument());
     }
 }
コード例 #9
0
 public static WmlDocument AcceptRevisions(WmlDocument document)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
         {
             AcceptRevisions(doc);
         }
         return(streamDoc.GetModifiedWmlDocument());
     }
 }
コード例 #10
0
 public static WmlDocument AcceptRevisions(WmlDocument document)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
         {
             AcceptRevisions(doc);
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #11
0
 public static WmlDocument SimplifyMarkup(WmlDocument doc, SimplifyMarkupSettings settings)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             SimplifyMarkup(document, settings);
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #12
0
 public static string RetrieveListItem(WmlDocument document,
                                       XElement paragraph, string bulletReplacementString)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument wdoc = streamDoc.GetWordprocessingDocument())
         {
             return(RetrieveListItem(wdoc, paragraph, bulletReplacementString));
         }
     }
 }
コード例 #13
0
 public static WmlDocument AddTof(WmlDocument document, string xPath, string switches, int?rightTabPos)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
         {
             AddTof(doc, xPath, switches, rightTabPos);
         }
         return(streamDoc.GetModifiedWmlDocument());
     }
 }
コード例 #14
0
 /// <summary>
 /// Get the specified footer from the document
 /// </summary>
 /// <param name="type">The footer part type</param>
 /// <returns>the XDocument containing the footer</returns>
 public static XDocument GetFooter(WmlDocument doc, FooterType type, int sectionIndex)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
     {
         OpenXmlPart footer = GetFooterPart(document, type, sectionIndex);
         if (footer != null)
             return footer.GetXDocument();
         return null;
     }
 }
コード例 #15
0
 public static WmlDocument AssembleFormatting(WmlDocument document, FormattingAssemblerSettings settings)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
         {
             AssembleFormatting(doc, settings);
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #16
0
 public static WmlDocument SearchAndReplace(WmlDocument doc, string search, string replace, bool matchCase)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             SearchAndReplace(document, search, replace, matchCase);
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #17
0
 public static string RetrieveListItem(WmlDocument document,
     XElement paragraph, string bulletReplacementString)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument wdoc = streamDoc.GetWordprocessingDocument())
         {
             return RetrieveListItem(wdoc, paragraph, bulletReplacementString);
         }
     }
 }
コード例 #18
0
 public static WmlDocument SimplifyMarkup(WmlDocument doc, SimplifyMarkupSettings settings)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             SimplifyMarkup(document, settings);
         }
         return(streamDoc.GetModifiedWmlDocument());
     }
 }
コード例 #19
0
        /// <summary>
        /// Sets the document background image
        /// </summary>
        /// <param name="imagePath">Path of the background image</param>
        public static OpenXmlPowerToolsDocument SetImage(WmlDocument doc, string imagePath)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument mainDocument = document.MainDocumentPart.GetXDocument();

                    // Adds the image to the package
                    ImagePart imagePart   = document.MainDocumentPart.AddImagePart(ImagePartType.Bmp);
                    Stream    imageStream = new StreamReader(imagePath).BaseStream;
                    byte[]    imageBytes  = new byte[imageStream.Length];
                    imageStream.Read(imageBytes, 0, imageBytes.Length);
                    imagePart.GetStream().Write(imageBytes, 0, imageBytes.Length);

                    // Creates a "background" element relating the image and the document

                    // If the background element already exists, deletes it
                    XElement backgroundElement = BackgroundElement(document);
                    if (backgroundElement != null)
                    {
                        backgroundElement.Remove();
                    }

                    // Background element construction
                    mainDocument.Root.Add(
                        new XElement(ns + "background",
                                     new XAttribute(ns + "color", defaultBackgroundColor),
                                     new XElement(vmlns + "background",
                                                  new XAttribute(vmlns + "id", defaultVmlBackgroundImageId),
                                                  new XAttribute(officens + "bwmode", defaultBWMode),
                                                  new XAttribute(officens + "targetscreensize", defaultTargetScreenSize),
                                                  new XElement(vmlns + "fill",
                                                               new XAttribute(relationshipsns + "id", document.MainDocumentPart.GetIdOfPart(imagePart)),
                                                               new XAttribute("recolor", defaultImageRecolor),
                                                               new XAttribute("type", defaultImageType)
                                                               )
                                                  )
                                     )
                        );


                    // Enables background displaying by adding "displayBackgroundShape" tag
                    if (SettingAccessor.DisplayBackgroundShapeElements(document) == null)
                    {
                        SettingAccessor.AddBackgroundShapeElement(document);
                    }

                    document.MainDocumentPart.PutXDocument();
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #20
0
 /// <summary>
 /// Get the specified header from the document
 /// </summary>
 /// <param name="type">The header part type</param>
 /// <returns>A XDocument containing the header</returns>
 public static XDocument GetHeader(WmlDocument doc, HeaderType type, int sectionIndex)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             OpenXmlPart header = GetHeaderPart(document, type, sectionIndex);
             if (header != null)
             {
                 return(header.GetXDocument());
             }
             return(null);
         }
 }
コード例 #21
0
ファイル: CustomXmlAccessor.cs プロジェクト: joyoon/mb
 /// <summary>
 /// Searches for a custom Xml part with a given name
 /// </summary>
 /// <param name="xmlPartName">Name of custom Xml part</param>
 /// <returns>XDocument with customXml part loaded</returns>
 public static XDocument Find(WmlDocument doc, string xmlPartName)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         WordprocessingDocument document = streamDoc.GetWordprocessingDocument();
         string partName = "/" + xmlPartName;
         var customXmlPart =
             document.MainDocumentPart.CustomXmlParts.Where(
                 t => t.Uri.OriginalString.EndsWith(partName, System.StringComparison.OrdinalIgnoreCase)
             ).FirstOrDefault();
         if (customXmlPart == null)
             throw new ArgumentException("Part name '" + xmlPartName + "' not found.");
         return customXmlPart.GetXDocument();
     }
 }
コード例 #22
0
        public static XElement GetDocxMetrics(WmlDocument wmlDoc, MetricsGetterSettings settings)
        {
            WmlDocument converted = new WmlDocument(wmlDoc, true);
            WmlDocument noTrackedRevisions = new WmlDocument(converted);

            try
            {
                using (OpenXmlMemoryStreamDocument noTrackedStreamDoc = new OpenXmlMemoryStreamDocument(noTrackedRevisions))
                using (WordprocessingDocument noTrackedDocument = noTrackedStreamDoc.GetWordprocessingDocument())
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(converted))
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    if (RevisionAccepter.HasTrackedRevisions(noTrackedDocument))
                        RevisionAccepter.AcceptRevisions(noTrackedDocument);
                    return GetWmlMetrics(converted.FileName, false, document, noTrackedDocument, settings);
                }
            }
            catch (OpenXmlPowerToolsException e)
            {
                if (e.ToString().Contains("Invalid Hyperlink"))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        WmlDocument fixedWmlDoc = new WmlDocument(converted);
                        ms.Write(converted.DocumentByteArray, 0, converted.DocumentByteArray.Length);
#if !NET35
                        UriFixer.FixInvalidUri(ms, brokenUri => FixUri(brokenUri));
#endif
                        converted = new WmlDocument("dummy.docx", ms.ToArray());
                    }
                    noTrackedRevisions = new WmlDocument(converted);
                    using (OpenXmlMemoryStreamDocument noTrackedStreamDoc = new OpenXmlMemoryStreamDocument(noTrackedRevisions))
                    using (WordprocessingDocument noTrackedDocument = noTrackedStreamDoc.GetWordprocessingDocument())
                    using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(converted))
                    using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                    {
                        if (RevisionAccepter.HasTrackedRevisions(noTrackedDocument))
                            RevisionAccepter.AcceptRevisions(noTrackedDocument);
                        return GetWmlMetrics(converted.FileName, true, document, noTrackedDocument, settings);
                    }
                }
            }
            var metrics = new XElement(H.Metrics,
                new XAttribute(H.FileName, converted.FileName),
                new XAttribute(H.FileType, "WordprocessingML"),
                new XAttribute(H.Error, "Unknown error, metrics not determined"));
            return metrics;
        }
コード例 #23
0
 /// <summary>
 /// Sets a new styles part inside the document
 /// </summary>
 /// <param name="newStylesDocument">Path of styles definition file</param>
 public static OpenXmlPowerToolsDocument SetStylePart(WmlDocument doc, XDocument newStylesDocument)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             // Replaces XDocument with the style file to transfer
             if (document.MainDocumentPart.StyleDefinitionsPart == null)
             {
                 document.MainDocumentPart.AddNewPart <StyleDefinitionsPart>();
             }
             document.MainDocumentPart.StyleDefinitionsPart.PutXDocument(newStylesDocument);
         }
         return(streamDoc.GetModifiedDocument());
     }
 }
コード例 #24
0
        public static IEnumerable <ValidationErrorInfo> GetOpenXmlValidationErrors(string fileName,
                                                                                   string officeVersion)
        {
            FileFormatVersions fileFormatVersion;

            if (!Enum.TryParse(officeVersion, out fileFormatVersion))
            {
                fileFormatVersion = FileFormatVersions.Office2013;
            }

            FileInfo fi = new FileInfo(fileName);

            if (Util.IsWordprocessingML(fi.Extension))
            {
                WmlDocument wml = new WmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wml))
                    using (WordprocessingDocument wDoc = streamDoc.GetWordprocessingDocument())
                    {
                        OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                        var errors = validator.Validate(wDoc);
                        return(errors.ToList());
                    }
            }
            else if (Util.IsSpreadsheetML(fi.Extension))
            {
                SmlDocument Sml = new SmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(Sml))
                    using (SpreadsheetDocument wDoc = streamDoc.GetSpreadsheetDocument())
                    {
                        OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                        var errors = validator.Validate(wDoc);
                        return(errors.ToList());
                    }
            }
            else if (Util.IsPresentationML(fi.Extension))
            {
                PmlDocument Pml = new PmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(Pml))
                    using (PresentationDocument wDoc = streamDoc.GetPresentationDocument())
                    {
                        OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                        var errors = validator.Validate(wDoc);
                        return(errors.ToList());
                    }
            }
            return(Enumerable.Empty <ValidationErrorInfo>());
        }
コード例 #25
0
 /// <summary>
 /// Searches for a custom Xml part with a given name
 /// </summary>
 /// <param name="xmlPartName">Name of custom Xml part</param>
 /// <returns>XDocument with customXml part loaded</returns>
 public static XDocument Find(WmlDocument doc, string xmlPartName)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         WordprocessingDocument document = streamDoc.GetWordprocessingDocument();
         string partName      = "/" + xmlPartName;
         var    customXmlPart =
             document.MainDocumentPart.CustomXmlParts.Where(
                 t => t.Uri.OriginalString.EndsWith(partName, System.StringComparison.OrdinalIgnoreCase)
                 ).FirstOrDefault();
         if (customXmlPart == null)
         {
             throw new ArgumentException("Part name '" + xmlPartName + "' not found.");
         }
         return(customXmlPart.GetXDocument());
     }
 }
コード例 #26
0
        public static OpenXmlPowerToolsDocument Lock(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    //Finds the settings part
                    XDocument settingsDocument;
                    XElement  documentProtectionElement = null;
                    if (document.MainDocumentPart.DocumentSettingsPart == null)
                    {
                        //If settings part does not exist creates a new one
                        DocumentSettingsPart settingsPart = document.MainDocumentPart.AddNewPart <DocumentSettingsPart>();
                        settingsDocument = settingsPart.GetXDocument();
                        settingsDocument.Add(new XElement(W.settings,
                                                          new XAttribute(XNamespace.Xmlns + "w", W.w),
                                                          new XAttribute(XNamespace.Xmlns + "r", R.r)));
                    }
                    else
                    {
                        //If the settings part does exist looks if documentProtection has been included
                        settingsDocument          = document.MainDocumentPart.DocumentSettingsPart.GetXDocument();
                        documentProtectionElement = settingsDocument.Element(W.settings).Element(W.documentProtection);
                    }

                    //Creates the documentProtection element, or edits it if it exists
                    if (documentProtectionElement == null)
                    {
                        settingsDocument
                        .Element(W.settings)
                        .Add(
                            new XElement(W.documentProtection,
                                         new XAttribute(W.edit, "readOnly")
                                         )
                            );
                    }
                    else
                    {
                        documentProtectionElement.SetAttributeValue(W.edit, "readOnly");
                    }
                    document.MainDocumentPart.DocumentSettingsPart.PutXDocument();
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #27
0
ファイル: CustomXmlAccessor.cs プロジェクト: joyoon/mb
        /// <summary>
        /// Replaces a previously existing customXml part by another one
        /// </summary>
        /// <param name="customXmlDocument">XDocument of part to replace inside the document package</param>
        /// <param name="partNameOnly">Name of the part.</param>
        public static OpenXmlPowerToolsDocument SetDocument(WmlDocument doc, XDocument customXmlDocument, string partNameOnly)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    string partName = "/" + partNameOnly;
                    var customXmlPart = document.MainDocumentPart.CustomXmlParts.Where(
                            t => t.Uri.OriginalString.EndsWith(partName, System.StringComparison.OrdinalIgnoreCase)
                        ).FirstOrDefault();

                    if (customXmlPart == null)
                        customXmlPart = document.MainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
                    customXmlPart.PutXDocument(customXmlDocument);
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #28
0
        /// <summary>
        /// Removes all of the comments existing in the document
        /// </summary>
        public static OpenXmlPowerToolsDocument RemoveAll(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    //Removes comment-related tags inside the main document part
                    IEnumerable<XElement> commentReferences = CommentReferences(document).ToList();
                    commentReferences.Remove();
                    document.MainDocumentPart.PutXDocument();

                    WordprocessingCommentsPart commentsPart = document.MainDocumentPart.WordprocessingCommentsPart;
                    if (commentsPart != null)
                        commentsPart.RemovePart();
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #29
0
        /// <summary>
        /// Replaces a previously existing customXml part by another one
        /// </summary>
        /// <param name="customXmlDocument">XDocument of part to replace inside the document package</param>
        /// <param name="partNameOnly">Name of the part.</param>
        public static OpenXmlPowerToolsDocument SetDocument(WmlDocument doc, XDocument customXmlDocument, string partNameOnly)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    string partName      = "/" + partNameOnly;
                    var    customXmlPart = document.MainDocumentPart.CustomXmlParts.Where(
                        t => t.Uri.OriginalString.EndsWith(partName, System.StringComparison.OrdinalIgnoreCase)
                        ).FirstOrDefault();

                    if (customXmlPart == null)
                    {
                        customXmlPart = document.MainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
                    }
                    customXmlPart.PutXDocument(customXmlDocument);
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #30
0
        /// <summary>
        /// Removes all of the comments existing in the document
        /// </summary>
        public static OpenXmlPowerToolsDocument RemoveAll(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    //Removes comment-related tags inside the main document part
                    IEnumerable <XElement> commentReferences = CommentReferences(document).ToList();
                    commentReferences.Remove();
                    document.MainDocumentPart.PutXDocument();

                    WordprocessingCommentsPart commentsPart = document.MainDocumentPart.WordprocessingCommentsPart;
                    if (commentsPart != null)
                    {
                        commentsPart.RemovePart();
                    }
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #31
0
        public static void SaveImageToFile(WmlDocument doc, string fileName)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument mainDocument = document.MainDocumentPart.GetXDocument();
                    XElement  fillElement  = mainDocument.Descendants(W.background).Descendants(VML.fill).FirstOrDefault();
                    if (fillElement != null)
                    {
                        string      imageRelationshipId = fillElement.Attribute(R.id).Value;
                        OpenXmlPart imagePart           = document.MainDocumentPart.GetPartById(imageRelationshipId);

                        // Gets the image name (path stripped)
                        string imagePath = imagePart.Uri.OriginalString;

                        // Writes the image outside the package
                        OpenXmlPowerToolsDocument.SavePartAs(imagePart, fileName);
                    }
                }
        }
コード例 #32
0
        public static string GetImageFileName(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
            {
                XDocument mainDocument = document.MainDocumentPart.GetXDocument();
                XElement fillElement = mainDocument.Descendants(W.background).Descendants(VML.fill).FirstOrDefault();
                if (fillElement != null)
                {
                    string imageRelationshipId = fillElement.Attribute(R.id).Value;
                    OpenXmlPart imagePart = document.MainDocumentPart.GetPartById(imageRelationshipId);

                    // Gets the image name (path stripped)
                    string imagePath = imagePart.Uri.OriginalString;
                    return imagePath.Substring(imagePath.LastIndexOf('/') + 1);
                }
                else
                    return string.Empty;
            }
        }
コード例 #33
0
 /// <summary>
 /// Gets the document structure related to watermark description
 /// </summary>
 /// <returns>Document structure related to watermark description</returns>
 public static IEnumerable<XElement> GetWatermark(WmlDocument doc)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
     {
         //  to get the watermark text, we have to look inside the document
         //  get the default header reference and get the header reference id part
         XElement defaultHeaderReference = HeaderAccessor.GetHeaderReference(document, HeaderType.Default, 0);
         if (defaultHeaderReference != null)
         {
             string headerReferenceId = defaultHeaderReference.Attribute(relationshipsns + "id").Value;
             OpenXmlPart headerPart = document.MainDocumentPart.GetPartById(headerReferenceId);
             if (headerPart != null)
             {
                 XDocument headerPartXml = headerPart.GetXDocument();
                 return headerPartXml.Descendants(ns + "pict");
             }
         }
         return null;
     }
 }
コード例 #34
0
 /// <summary>
 /// Gets the document structure related to watermark description
 /// </summary>
 /// <returns>Document structure related to watermark description</returns>
 public static IEnumerable <XElement> GetWatermark(WmlDocument doc)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             //  to get the watermark text, we have to look inside the document
             //  get the default header reference and get the header reference id part
             XElement defaultHeaderReference = HeaderAccessor.GetHeaderReference(document, HeaderType.Default, 0);
             if (defaultHeaderReference != null)
             {
                 string      headerReferenceId = defaultHeaderReference.Attribute(relationshipsns + "id").Value;
                 OpenXmlPart headerPart        = document.MainDocumentPart.GetPartById(headerReferenceId);
                 if (headerPart != null)
                 {
                     XDocument headerPartXml = headerPart.GetXDocument();
                     return(headerPartXml.Descendants(ns + "pict"));
                 }
             }
             return(null);
         }
 }
コード例 #35
0
        public static string GetImageFileName(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument mainDocument = document.MainDocumentPart.GetXDocument();
                    XElement  fillElement  = mainDocument.Descendants(W.background).Descendants(VML.fill).FirstOrDefault();
                    if (fillElement != null)
                    {
                        string      imageRelationshipId = fillElement.Attribute(R.id).Value;
                        OpenXmlPart imagePart           = document.MainDocumentPart.GetPartById(imageRelationshipId);

                        // Gets the image name (path stripped)
                        string imagePath = imagePart.Uri.OriginalString;
                        return(imagePath.Substring(imagePath.LastIndexOf('/') + 1));
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
        }
コード例 #36
0
        public static object GetAllComments(WmlDocument doc, CommentFormat format)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    IEnumerable <XElement>     comments     = null;
                    WordprocessingCommentsPart commentsPart = document.MainDocumentPart.WordprocessingCommentsPart;
                    if (commentsPart != null)
                    {
                        XDocument commentsPartDocument = commentsPart.GetXDocument();
                        comments = commentsPartDocument.Element(W.comments).Elements(W.comment);
                    }
                    if (comments != null)
                    {
                        XDocument commentsDocument =
                            new XDocument(
                                new XElement(W.comments,
                                             new XAttribute(XNamespace.Xmlns + "w", W.w),
                                             comments
                                             )
                                );
                        switch (format)
                        {
                        case CommentFormat.PlainText:
                            return(commentsDocument.ToString());

                        case CommentFormat.Xml:
                            return(commentsDocument);

                        case CommentFormat.Docx:
                            return(CreateCommentsDocument(comments));
                        }
                    }
                    return(null);
                }
        }
コード例 #37
0
        public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, Image pictureToInsert, string name)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument xmlMainDocument = document.MainDocumentPart.GetXDocument();
                    ImagePart picturePart = null;
                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("w", mainns.NamespaceName);
                    IEnumerable<XElement> insertionPoints = xmlMainDocument.XPathSelectElements(xpathInsertionPoint, namespaceManager);

                    //make the insertion for each insertion point specified in the xpath query
                    foreach (XElement insertionPoint in insertionPoints)
                    {
                        if (picturePart == null)
                        {
                            //  Create the picture part in the package
                            picturePart = document.MainDocumentPart.AddImagePart(GetImagePartType(pictureToInsert.RawFormat));
                        }

                        //  the pictures in the main document part goes in a very long xml, wich specifies the way the picture
                        //  has to be placed using drawingXml.
                        insertionPoint.AddAfterSelf(
                            new XElement(mainns + "p",
                                new XElement(mainns + "r",
                                    new XElement(mainns + "drawing",
                                        new XElement(wordprocessingDrawingns + "inline",
                                            new XElement(wordprocessingDrawingns + "extent",
                                                new XAttribute("cx", pictureToInsert.Width * pixelsPerEmu),
                                                new XAttribute("cy", pictureToInsert.Height * pixelsPerEmu)
                                            ),
                                            new XElement(wordprocessingDrawingns + "docPr",
                                                new XAttribute("name", name),
                                                new XAttribute("id", "1")
                                            ),
                                            new XElement(drawingmlMainns + "graphic",
                                                new XAttribute(XNamespace.Xmlns + "a", drawingmlMainns.NamespaceName),
                                                new XElement(drawingmlMainns + "graphicData",
                                                    new XAttribute("uri", picturens.NamespaceName),
                                                    new XElement(picturens + "pic",
                                                        new XAttribute(XNamespace.Xmlns + "pic", picturens.NamespaceName),
                                                        new XElement(picturens + "nvPicPr",
                                                            new XElement(picturens + "cNvPr",
                                                                new XAttribute("id", "0"),
                                                                new XAttribute("name", name)
                                                            ),
                                                            new XElement(picturens + "cNvPicPr")
                                                        ),
                                                        new XElement(picturens + "blipFill",
                                                            new XElement(drawingmlMainns + "blip",
                                                                new XAttribute(relationshipns + "embed", document.MainDocumentPart.GetIdOfPart(picturePart))
                                                            ),
                                                            new XElement(drawingmlMainns + "stretch",
                                                                new XElement(drawingmlMainns + "fillRect")
                                                            )
                                                        ),
                                                        new XElement(picturens + "spPr",
                                                            new XElement(drawingmlMainns + "xfrm",
                                                                new XElement(drawingmlMainns + "off",
                                                                    new XAttribute("x", "0"),
                                                                    new XAttribute("y", "0")
                                                                ),
                                                                new XElement(drawingmlMainns + "ext",
                                                                    new XAttribute("cx", pictureToInsert.Width * pixelsPerEmu),
                                                                    new XAttribute("cy", pictureToInsert.Height * pixelsPerEmu)
                                                                )
                                                            ),
                                                            new XElement(drawingmlMainns + "prstGeom",
                                                                new XAttribute("prst", "rect")
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        );
                    }
                    if (picturePart != null)
                    {
                        Stream partStream = picturePart.GetStream(FileMode.Create, FileAccess.ReadWrite);
                        pictureToInsert.Save(partStream, pictureToInsert.RawFormat);
                    }
                    else
                        throw new ArgumentException("The xpath query did not return a valid location.");
                    document.MainDocumentPart.PutXDocument();
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #38
0
        public static WmlDocument AppendParagraphToDocument(
            WmlDocument wmlDoc,
            string strParagraph,
            bool isBold,
            bool isItalic,
            bool isUnderline,
            string foreColor,
            string backColor,
            string styleName)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlDoc))
            {
                using (WordprocessingDocument wDoc = streamDoc.GetWordprocessingDocument())
                {
                    StyleDefinitionsPart part = wDoc.MainDocumentPart.StyleDefinitionsPart;

                    Body body = wDoc.MainDocumentPart.Document.Body;

                    SectionProperties sectionProperties = body.Elements <SectionProperties>().FirstOrDefault();

                    Paragraph     paragraph     = new Paragraph();
                    Run           run           = paragraph.AppendChild(new Run());
                    RunProperties runProperties = new RunProperties();

                    if (isBold)
                    {
                        runProperties.AppendChild(new Bold());
                    }

                    if (isItalic)
                    {
                        runProperties.AppendChild(new Italic());
                    }


                    if (!string.IsNullOrEmpty(foreColor))
                    {
                        int colorValue = System.Drawing.Color.FromName(foreColor).ToArgb();
                        if (colorValue == 0)
                        {
                            throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));
                        }

                        string ColorHex = string.Format("{0:x6}", colorValue);
                        runProperties.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Color()
                        {
                            Val = ColorHex.Substring(2)
                        });
                    }

                    if (isUnderline)
                    {
                        runProperties.AppendChild(new Underline()
                        {
                            Val = UnderlineValues.Single
                        });
                    }

                    if (!string.IsNullOrEmpty(backColor))
                    {
                        int colorShade = System.Drawing.Color.FromName(backColor).ToArgb();
                        if (colorShade == 0)
                        {
                            throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));
                        }

                        string ColorShadeHex = string.Format("{0:x6}", colorShade);
                        runProperties.AppendChild(new Shading()
                        {
                            Fill = ColorShadeHex.Substring(2), Val = ShadingPatternValues.Clear
                        });
                    }

                    if (!string.IsNullOrEmpty(styleName))
                    {
                        Style style = part.Styles.Elements <Style>().Where(s => s.StyleId == styleName).FirstOrDefault();
                        //if the specified style is not present in word document add it
                        if (style == null)
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                #region Default.dotx Template has been used to get all the paragraph styles
                                string base64 =
                                    @"UEsDBBQABgAIAAAAIQDTMB8uXgEAACAFAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbLSUy27CMBBF
95X6D5G3VWLooqoqAos+li1S6QcYewJW/ZI9vP6+EwKoqiCRCmwiJTP33jNWxoPR2ppsCTFp70rW
L3osAye90m5Wsq/JW/7IsoTCKWG8g5JtILHR8PZmMNkESBmpXSrZHDE8cZ7kHKxIhQ/gqFL5aAXS
a5zxIOS3mAG/7/UeuPQOwWGOtQcbDl6gEguD2euaPjckEUxi2XPTWGeVTIRgtBRIdb506k9Kvkso
SLntSXMd0h01MH40oa6cDtjpPuhoolaQjUXEd2Gpi698VFx5ubCkLNptjnD6qtISDvraLUQvISU6
c2sKBBtoAiis0G7Pf5Ij4cZAujxF49sdD4gkuAbAzrkTYQXTz6tR/DLvBKkodyKmBi6PcbDuhEDa
QGie/bM5tjZtkdQ5jj4k2uj4j7H3K1urcxo4QETd/tcdEsn67Pmgvg0UqCPZfHu/DX8AAAD//wMA
UEsDBB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AMQMAABwAAAAAAAAAAAAAAAAAlAYAAHdvcmQvX3JlbHMvZG9jdW1lbnQu
eG1sLnJlbHNQSwECLQAUAAYACADRagZBeuUzdzMCAACQBQAAEQAAAAAAAAAAAAAAAADCBwAAd29y
ZC9kb2N1bWVudC54bWxQSwECLQAUAAYACADRagZB3iZxVZoCAAAzBwAAEgAAAAAAAAAAAAAAAAAk
CgAAd29yZC9mb250VGFibGUueG1sUEsBAi0AFAAEAAgA0WoGQYaCXUkdBAAAeQkAABEAAAAAAAAA
AAAAAAAA7gwAAHdvcmQvc2V0dGluZ3MueG1sUEsBAi0AFAAEAAgA0WoGQSv37OFTEgAAFa0AAA8A
AAAAAAAAAAAAAAAAOhEAAHdvcmQvc3R5bGVzLnhtbFBLAQItABQABgAIANFqBkEJ28MF3QYAAFAb
AAAVAAAAAAAAAAAAAAAAALojAAB3b3JkL3RoZW1lL3RoZW1lMS54bWxQSwECLQAUAAYACADRagZB
joxzCXABAAD0AQAAFAAAAAAAAAAAAAAAAADKKgAAd29yZC93ZWJTZXR0aW5ncy54bWxQSwUGAAAA
AAsACwDBAgAAbCwAAAAA";
                                #endregion

                                char[] base64CharArray = base64.Where(c => c != '\r' && c != '\n').ToArray();
                                byte[] byteArray       = System.Convert.FromBase64CharArray(base64CharArray, 0, base64CharArray.Length);
                                memoryStream.Write(byteArray, 0, byteArray.Length);

                                using (WordprocessingDocument defaultDotx = WordprocessingDocument.Open(memoryStream, true))
                                {
                                    //Get the specified style from Default.dotx template for paragraph
                                    Style templateStyle = defaultDotx.MainDocumentPart.StyleDefinitionsPart.Styles.Elements <Style>().Where(s => s.StyleId == styleName && s.Type == StyleValues.Paragraph).FirstOrDefault();

                                    //Check if the style is proper style. Ex, Heading1, Heading2
                                    if (templateStyle == null)
                                    {
                                        throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified style name {0} is unsupported, Please specify the valid style. Ex, Heading1, Heading2, Title", styleName));
                                    }
                                    else
                                    {
                                        part.Styles.Append((templateStyle.CloneNode(true)));
                                    }
                                }
                            }
                        }

                        paragraph.ParagraphProperties = new ParagraphProperties(new ParagraphStyleId()
                        {
                            Val = styleName
                        });
                    }

                    run.AppendChild(runProperties);
                    run.AppendChild(new Text(strParagraph));

                    if (sectionProperties != null)
                    {
                        body.InsertBefore(paragraph, sectionProperties);
                    }
                    else
                    {
                        body.AppendChild(paragraph);
                    }
                }
                return(streamDoc.GetModifiedWmlDocument());
            }
        }
コード例 #39
0
        /// <summary>
        /// Inserts a watermark text inside a document
        /// </summary>
        /// <param name="watermarkText">text to show in the watermark</param>
        /// <param name="diagonalOrientation">specify that the text orientation will be in a diagonal way</param>
        public static OpenXmlPowerToolsDocument InsertWatermark(WmlDocument doc, string watermarkText, bool diagonalOrientation)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    Collection<XDocument> headers = new Collection<XDocument>();

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.First, 0) == null)
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.First));
                    else
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.First, 0));

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.Even, 0) == null)
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.Even));
                    else
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.Even, 0));

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.Default, 0) == null)
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.Default));
                    else
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.Default, 0));

                    foreach (XDocument header in headers)
                    {
                        var runElement = header.Descendants(ns + "r").FirstOrDefault();
                        if (runElement == null)
                        {
                            header.Root.Add(
                                new XElement(ns + "sdt",
                                    new XElement(ns + "sdtContent",
                                        new XElement(ns + "p",
                                            new XElement(ns + "pPr",
                                                new XElement(ns + "pStyle",
                                                    new XAttribute(ns + "val", "Header")
                                                )
                                            ),
                                            runElement = new XElement(ns + "r")
                                        )
                                    )
                                )
                            );

                        }
                        runElement.AddBeforeSelf(CreateWatermarkVml(watermarkText, diagonalOrientation));
                    }

                    HeaderAccessor.GetHeaderPart(document, HeaderType.First, 0).PutXDocument();
                    HeaderAccessor.GetHeaderPart(document, HeaderType.Even, 0).PutXDocument();
                    HeaderAccessor.GetHeaderPart(document, HeaderType.Default, 0).PutXDocument();
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #40
0
        /// <summary>
        /// Inserts a watermark text inside a document
        /// </summary>
        /// <param name="watermarkText">text to show in the watermark</param>
        /// <param name="diagonalOrientation">specify that the text orientation will be in a diagonal way</param>
        public static OpenXmlPowerToolsDocument InsertWatermark(WmlDocument doc, string watermarkText, bool diagonalOrientation)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    Collection <XDocument> headers = new Collection <XDocument>();

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.First, 0) == null)
                    {
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.First));
                    }
                    else
                    {
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.First, 0));
                    }

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.Even, 0) == null)
                    {
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.Even));
                    }
                    else
                    {
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.Even, 0));
                    }

                    if (HeaderAccessor.GetHeaderReference(document, HeaderType.Default, 0) == null)
                    {
                        headers.Add(HeaderAccessor.AddNewHeader(document, HeaderType.Default));
                    }
                    else
                    {
                        headers.Add(HeaderAccessor.GetHeader(document, HeaderType.Default, 0));
                    }

                    foreach (XDocument header in headers)
                    {
                        var runElement = header.Descendants(ns + "r").FirstOrDefault();
                        if (runElement == null)
                        {
                            header.Root.Add(
                                new XElement(ns + "sdt",
                                             new XElement(ns + "sdtContent",
                                                          new XElement(ns + "p",
                                                                       new XElement(ns + "pPr",
                                                                                    new XElement(ns + "pStyle",
                                                                                                 new XAttribute(ns + "val", "Header")
                                                                                                 )
                                                                                    ),
                                                                       runElement = new XElement(ns + "r")
                                                                       )
                                                          )
                                             )
                                );
                        }
                        runElement.AddBeforeSelf(CreateWatermarkVml(watermarkText, diagonalOrientation));
                    }

                    HeaderAccessor.GetHeaderPart(document, HeaderType.First, 0).PutXDocument();
                    HeaderAccessor.GetHeaderPart(document, HeaderType.Even, 0).PutXDocument();
                    HeaderAccessor.GetHeaderPart(document, HeaderType.Default, 0).PutXDocument();
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #41
0
 public static bool HasTrackedRevisions(WmlDocument document)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document))
     {
         using (WordprocessingDocument wdoc = streamDoc.GetWordprocessingDocument())
         {
             return RevisionAccepter.HasTrackedRevisions(wdoc);
         }
     }
 }
コード例 #42
0
        public static WmlDocument MergeComments(WmlDocument document1, WmlDocument document2,
                                                bool ensureLocked)
        {
            WmlDocument cDoc1 = new WmlDocument(document1);
            WmlDocument cDoc2 = new WmlDocument(document2);

            using (OpenXmlMemoryStreamDocument streamDoc1 = new OpenXmlMemoryStreamDocument(cDoc1))
                using (WordprocessingDocument doc1 = streamDoc1.GetWordprocessingDocument())
                    using (OpenXmlMemoryStreamDocument streamDoc2 = new OpenXmlMemoryStreamDocument(cDoc2))
                        using (WordprocessingDocument doc2 = streamDoc2.GetWordprocessingDocument())
                        {
                            SimplifyMarkupSettings mss = new SimplifyMarkupSettings()
                            {
                                RemoveProof          = true,
                                RemoveRsidInfo       = true,
                                RemoveGoBackBookmark = true,
                            };
                            MarkupSimplifier.SimplifyMarkup(doc1, mss);
                            MarkupSimplifier.SimplifyMarkup(doc2, mss);

                            // If documents don't contain the same content, then don't attempt to merge comments.
                            bool same = DocumentComparer.CompareDocuments(doc1, doc2);
                            if (!same)
                            {
                                throw new CommentMergerDifferingContentsException(
                                          "Documents do not contain the same content");
                            }

                            if (doc1.MainDocumentPart.WordprocessingCommentsPart == null &&
                                doc2.MainDocumentPart.WordprocessingCommentsPart == null)
                            {
                                return(new WmlDocument(document1));
                            }
                            if (doc1.MainDocumentPart.WordprocessingCommentsPart != null &&
                                doc2.MainDocumentPart.WordprocessingCommentsPart == null)
                            {
                                return(new WmlDocument(document1));
                            }
                            if (doc1.MainDocumentPart.WordprocessingCommentsPart == null &&
                                doc2.MainDocumentPart.WordprocessingCommentsPart != null)
                            {
                                return(new WmlDocument(document2));
                            }
                            // If either of the documents have no comments, then return the other one.
                            if (!doc1.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root
                                .Elements(W.comment).Any())
                            {
                                return(new WmlDocument(document2));
                            }
                            if (!doc2.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root
                                .Elements(W.comment).Any())
                            {
                                return(new WmlDocument(document1));
                            }

                            if (ensureLocked)
                            {
                                // If either document is not locked (allowing only commenting), don't attempt to
                                // merge comments.
                                if (doc1.ExtendedFilePropertiesPart.GetXDocument().Root
                                    .Element(EP.DocSecurity).Value != "8")
                                {
                                    throw new CommentMergerUnlockedDocumentException(
                                              "Document1 is not locked");
                                }
                                if (doc2.ExtendedFilePropertiesPart.GetXDocument().Root
                                    .Element(EP.DocSecurity).Value != "8")
                                {
                                    throw new CommentMergerUnlockedDocumentException(
                                              "Document2 is not locked");
                                }
                            }

                            RenumberCommentsInDoc2(doc1, doc2);

                            WmlDocument destDoc = new WmlDocument(document1);

                            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(destDoc))
                            {
                                using (WordprocessingDocument destWDoc = streamDoc.GetWordprocessingDocument())
                                {
                                    // Merge the comments part.
                                    XDocument commentsPartXDoc = new XDocument(
                                        new XElement(W.comments,
                                                     new XAttribute(XNamespace.Xmlns + "w", W.w),
                                                     doc1.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root.Elements(),
                                                     doc2.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root.Elements()));
                                    destWDoc.MainDocumentPart.WordprocessingCommentsPart.PutXDocument(commentsPartXDoc);

                                    MergeCommentsInPart(doc1.MainDocumentPart, doc2.MainDocumentPart,
                                                        destWDoc.MainDocumentPart, commentsPartXDoc);
                                }
                                return(streamDoc.GetModifiedWmlDocument());
                            }
                        }
        }
コード例 #43
0
        /// <summary>
        /// Gets the document theme
        /// </summary>
        public static OpenXmlPowerToolsDocument GetTheme(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument sourceStreamDoc = new OpenXmlMemoryStreamDocument(doc))
            using (WordprocessingDocument document = sourceStreamDoc.GetWordprocessingDocument())
            {
                // Loads the theme part main file
                ThemePart theme = document.MainDocumentPart.ThemePart;
                if (theme != null)
                {
                    XDocument themeDocument = theme.GetXDocument();

                    // Creates the theme package (thmx file)
                    using (OpenXmlMemoryStreamDocument streamDoc = OpenXmlMemoryStreamDocument.CreatePackage())
                    {
                        using (Package themePackage = streamDoc.GetPackage())
                        {
                            // Creates the theme manager part on the new package and loads default content
                            PackagePart newThemeManagerPart = themePackage.CreatePart(new Uri("/theme/theme/themeManager.xml", UriKind.RelativeOrAbsolute), "application/vnd.openxmlformats-officedocument.themeManager+xml");
                            themePackage.CreateRelationship(newThemeManagerPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
                            using (XmlWriter xWriter = XmlWriter.Create(newThemeManagerPart.GetStream(FileMode.Create, FileAccess.Write)))
                            {
                                CreateEmptyThemeManager().WriteTo(xWriter);
                                xWriter.Flush();
                            }

                            // Creates the main theme part
                            PackagePart newThemePart = themePackage.CreatePart(new Uri("/theme/theme/" + theme.Uri.OriginalString.Substring(theme.Uri.OriginalString.LastIndexOf('/') + 1), UriKind.RelativeOrAbsolute), theme.ContentType);
                            newThemeManagerPart.CreateRelationship(newThemePart.Uri, TargetMode.Internal, theme.RelationshipType);

                            // Gets embeded part references
                            var embeddedItems =
                                themeDocument
                                .Descendants()
                                .Attributes(relationshipns + "embed");

                            foreach (IdPartPair partId in theme.Parts)
                            {
                                OpenXmlPart part = partId.OpenXmlPart;

                                // Creates the new media part inside the destination package
                                PackagePart newPart = themePackage.CreatePart(new Uri("/theme/media/" + part.Uri.OriginalString.Substring(part.Uri.OriginalString.LastIndexOf('/') + 1), UriKind.RelativeOrAbsolute), part.ContentType);
                                PackageRelationship relationship =
                                    newThemePart.CreateRelationship(newPart.Uri, TargetMode.Internal, part.RelationshipType);

                                // Copies binary content from original part to destination part
                                Stream partStream = part.GetStream(FileMode.Open, FileAccess.Read);
                                Stream newPartStream = newPart.GetStream(FileMode.Create, FileAccess.Write);
                                byte[] fileContent = new byte[partStream.Length];
                                partStream.Read(fileContent, 0, (int)partStream.Length);
                                newPartStream.Write(fileContent, 0, (int)partStream.Length);
                                newPartStream.Flush();

                                // Replaces old embed part reference with the freshly created one
                                XAttribute relationshipAttribute = embeddedItems.FirstOrDefault(e => e.Value == theme.GetIdOfPart(part));
                                if (relationshipAttribute != null)
                                    relationshipAttribute.Value = relationship.Id;
                            }

                            // Writes the updated theme XDocument into the destination package
                            using (XmlWriter newThemeWriter = XmlWriter.Create(newThemePart.GetStream(FileMode.Create, FileAccess.Write)))
                                themeDocument.WriteTo(newThemeWriter);
                        }
                        return streamDoc.GetModifiedDocument();
                    }
                }
                return null;
            }
        }
コード例 #44
0
        /// <summary>
        /// Set a new footer in a document
        /// </summary>
        /// <param name="footer">XDocument containing the footer to add in the document</param>
        /// <param name="type">The footer part type</param>
        public static OpenXmlPowerToolsDocument SetFooter(WmlDocument doc, XDocument footer, FooterType type, int sectionIndex)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    //  Removes the reference in the document.xml and the footer part if those already
                    //  exist
                    XElement footerReferenceElement = GetFooterReference(document, type, sectionIndex);
                    if (footerReferenceElement != null)
                    {
                        GetFooterPart(document, type, sectionIndex).RemovePart();
                        footerReferenceElement.Remove();
                    }

                    //  Add the new footer
                    FooterPart footerPart = document.MainDocumentPart.AddNewPart <FooterPart>();
                    footerPart.PutXDocument(footer);

                    //  If the document does not have a property section a new one must be created
                    if (SectionPropertiesElements(document).Count() == 0)
                    {
                        AddDefaultSectionProperties(document);
                    }

                    //  Creates the relationship of the footer inside the section properties in the document
                    string relID    = document.MainDocumentPart.GetIdOfPart(footerPart);
                    string kindName = "";
                    switch ((FooterType)type)
                    {
                    case FooterType.First:
                        kindName = "first";
                        break;

                    case FooterType.Even:
                        kindName = "even";
                        break;

                    case FooterType.Default:
                        kindName = "default";
                        break;
                    }

                    XElement sectionPropertyElement = SectionPropertiesElements(document).Skip(sectionIndex).FirstOrDefault();
                    if (sectionPropertyElement != null)
                    {
                        sectionPropertyElement.Add(
                            new XElement(ns + "footerReference",
                                         new XAttribute(ns + "type", kindName),
                                         new XAttribute(relationshipns + "id", relID)));

                        if (sectionPropertyElement.Element(ns + "titlePg") == null)
                        {
                            sectionPropertyElement.Add(
                                new XElement(ns + "titlePg")
                                );
                        }
                    }
                    document.MainDocumentPart.PutXDocument();

                    // add in the settings part the EvendAndOddHeaders. this element
                    // allow to see the odd and even footers and headers in the document.
                    SettingAccessor.AddEvenAndOddHeadersElement(document);
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #45
0
        public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, Image pictureToInsert, string name)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument           xmlMainDocument  = document.MainDocumentPart.GetXDocument();
                    ImagePart           picturePart      = null;
                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());
                    namespaceManager.AddNamespace("w", mainns.NamespaceName);
                    IEnumerable <XElement> insertionPoints = xmlMainDocument.XPathSelectElements(xpathInsertionPoint, namespaceManager);

                    //make the insertion for each insertion point specified in the xpath query
                    foreach (XElement insertionPoint in insertionPoints)
                    {
                        if (picturePart == null)
                        {
                            //  Create the picture part in the package
                            picturePart = document.MainDocumentPart.AddImagePart(GetImagePartType(pictureToInsert.RawFormat));
                        }

                        //  the pictures in the main document part goes in a very long xml, wich specifies the way the picture
                        //  has to be placed using drawingXml.
                        insertionPoint.AddAfterSelf(
                            new XElement(mainns + "p",
                                         new XElement(mainns + "r",
                                                      new XElement(mainns + "drawing",
                                                                   new XElement(wordprocessingDrawingns + "inline",
                                                                                new XElement(wordprocessingDrawingns + "extent",
                                                                                             new XAttribute("cx", pictureToInsert.Width * pixelsPerEmu),
                                                                                             new XAttribute("cy", pictureToInsert.Height * pixelsPerEmu)
                                                                                             ),
                                                                                new XElement(wordprocessingDrawingns + "docPr",
                                                                                             new XAttribute("name", name),
                                                                                             new XAttribute("id", "1")
                                                                                             ),
                                                                                new XElement(drawingmlMainns + "graphic",
                                                                                             new XAttribute(XNamespace.Xmlns + "a", drawingmlMainns.NamespaceName),
                                                                                             new XElement(drawingmlMainns + "graphicData",
                                                                                                          new XAttribute("uri", picturens.NamespaceName),
                                                                                                          new XElement(picturens + "pic",
                                                                                                                       new XAttribute(XNamespace.Xmlns + "pic", picturens.NamespaceName),
                                                                                                                       new XElement(picturens + "nvPicPr",
                                                                                                                                    new XElement(picturens + "cNvPr",
                                                                                                                                                 new XAttribute("id", "0"),
                                                                                                                                                 new XAttribute("name", name)
                                                                                                                                                 ),
                                                                                                                                    new XElement(picturens + "cNvPicPr")
                                                                                                                                    ),
                                                                                                                       new XElement(picturens + "blipFill",
                                                                                                                                    new XElement(drawingmlMainns + "blip",
                                                                                                                                                 new XAttribute(relationshipns + "embed", document.MainDocumentPart.GetIdOfPart(picturePart))
                                                                                                                                                 ),
                                                                                                                                    new XElement(drawingmlMainns + "stretch",
                                                                                                                                                 new XElement(drawingmlMainns + "fillRect")
                                                                                                                                                 )
                                                                                                                                    ),
                                                                                                                       new XElement(picturens + "spPr",
                                                                                                                                    new XElement(drawingmlMainns + "xfrm",
                                                                                                                                                 new XElement(drawingmlMainns + "off",
                                                                                                                                                              new XAttribute("x", "0"),
                                                                                                                                                              new XAttribute("y", "0")
                                                                                                                                                              ),
                                                                                                                                                 new XElement(drawingmlMainns + "ext",
                                                                                                                                                              new XAttribute("cx", pictureToInsert.Width * pixelsPerEmu),
                                                                                                                                                              new XAttribute("cy", pictureToInsert.Height * pixelsPerEmu)
                                                                                                                                                              )
                                                                                                                                                 ),
                                                                                                                                    new XElement(drawingmlMainns + "prstGeom",
                                                                                                                                                 new XAttribute("prst", "rect")
                                                                                                                                                 )
                                                                                                                                    )
                                                                                                                       )
                                                                                                          )
                                                                                             )
                                                                                )
                                                                   )
                                                      )
                                         )
                            );
                    }
                    if (picturePart != null)
                    {
                        Stream partStream = picturePart.GetStream(FileMode.Create, FileAccess.ReadWrite);
                        pictureToInsert.Save(partStream, pictureToInsert.RawFormat);
                    }
                    else
                    {
                        throw new ArgumentException("The xpath query did not return a valid location.");
                    }
                    document.MainDocumentPart.PutXDocument();
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #46
0
        private static void BuildDocument(List<Source> sources, WordprocessingDocument output)
        {
            if (RelationshipMarkup == null)
                RelationshipMarkup = new Dictionary<XName, XName[]>()
                {
                    //{ button,           new [] { image }},
                    { A.blip,             new [] { R.embed, R.link }},
                    { A.hlinkClick,       new [] { R.id }},
                    { A.relIds,           new [] { R.cs, R.dm, R.lo, R.qs }},
                    //{ a14:imgLayer,     new [] { R.embed }},
                    //{ ax:ocx,           new [] { R.id }},
                    { C.chart,            new [] { R.id }},
                    { C.externalData,     new [] { R.id }},
                    { C.userShapes,       new [] { R.id }},
                    { DGM.relIds,         new [] { R.cs, R.dm, R.lo, R.qs }},
                    { O.OLEObject,        new [] { R.id }},
                    { VML.fill,           new [] { R.id }},
                    { VML.imagedata,      new [] { R.href, R.id, R.pict }},
                    { VML.stroke,         new [] { R.id }},
                    { W.altChunk,         new [] { R.id }},
                    { W.attachedTemplate, new [] { R.id }},
                    { W.control,          new [] { R.id }},
                    { W.dataSource,       new [] { R.id }},
                    { W.embedBold,        new [] { R.id }},
                    { W.embedBoldItalic,  new [] { R.id }},
                    { W.embedItalic,      new [] { R.id }},
                    { W.embedRegular,     new [] { R.id }},
                    { W.footerReference,  new [] { R.id }},
                    { W.headerReference,  new [] { R.id }},
                    { W.headerSource,     new [] { R.id }},
                    { W.hyperlink,        new [] { R.id }},
                    { W.printerSettings,  new [] { R.id }},
                    { W.recipientData,    new [] { R.id }},  // Mail merge, not required
                    { W.saveThroughXslt,  new [] { R.id }},
                    { W.sourceFileName,   new [] { R.id }},  // Framesets, not required
                    { W.src,              new [] { R.id }},  // Mail merge, not required
                    { W.subDoc,           new [] { R.id }},  // Sub documents, not required
                    //{ w14:contentPart,  new [] { R.id }},
                    { WNE.toolbarData,    new [] { R.id }},
                };


            // This list is used to eliminate duplicate images
            List<ImageData> images = new List<ImageData>();
            XDocument mainPart = output.MainDocumentPart.GetXDocument();
            mainPart.Declaration.Standalone = "yes";
            mainPart.Declaration.Encoding = "UTF-8";
            mainPart.Root.ReplaceWith(
                new XElement(W.document, NamespaceAttributes,
                    new XElement(W.body)));
            if (sources.Count > 0)
            {
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(sources[0].WmlDocument))
                using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                {
                    CopyStartingParts(doc, output, images);
                }

                int sourceNum = 0;
                foreach (Source source in sources)
                {
                    if (source.InsertId != null)
                    {
                        while (true)
                        {
                            XDocument mainXDoc = output.MainDocumentPart.GetXDocument();
                            if (!mainXDoc.Descendants(PtOpenXml.Insert).Any(d => (string)d.Attribute(PtOpenXml.Id) == source.InsertId))
                                break;
                            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(source.WmlDocument))
                            using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                            {
#if TestForUnsupportedDocuments
                                // throws exceptions if a document contains unsupported content
                                TestForUnsupportedDocument(doc, sources.IndexOf(source));
#endif
                                List<XElement> contents = doc.MainDocumentPart.GetXDocument()
                                    .Root
                                    .Element(W.body)
                                    .Elements()
                                    .Skip(source.Start)
                                    .Take(source.Count)
                                    .ToList();
                                try
                                {
                                    AppendDocument(doc, output, contents, source.KeepSections, source.InsertId, images);
                                }
                                catch (DocumentBuilderInternalException dbie)
                                {
                                    if (dbie.Message.Contains("{0}"))
                                        throw new DocumentBuilderException(string.Format(dbie.Message, sourceNum));
                                    else
                                        throw dbie;
                                }
                            }
                        }
                    }
                    else
                    {
                        using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(source.WmlDocument))
                        using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                        {
#if TestForUnsupportedDocuments
                            // throws exceptions if a document contains unsupported content
                            TestForUnsupportedDocument(doc, sources.IndexOf(source));
#endif
                            List<XElement> contents = doc.MainDocumentPart.GetXDocument()
                                .Root
                                .Element(W.body)
                                .Elements()
                                .Skip(source.Start)
                                .Take(source.Count)
                                .ToList();
                            try
                            {
                                AppendDocument(doc, output, contents, source.KeepSections, null, images);
                            }
                            catch (DocumentBuilderInternalException dbie)
                            {
                                if (dbie.Message.Contains("{0}"))
                                    throw new DocumentBuilderException(string.Format(dbie.Message, sourceNum));
                                else
                                    throw dbie;
                            }
                        }
                    }
                    ++sourceNum;
                }
                if (!sources.Any(s => s.KeepSections))
                {
                    using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(sources[0].WmlDocument))
                    using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                    {
                        var sectPr = doc.MainDocumentPart.GetXDocument().Root.Element(W.body)
                            .Elements().Last();
                        if (sectPr.Name == W.sectPr)
                        {
                            AddSectionAndDependencies(doc, output, sectPr, images);
                            output.MainDocumentPart.GetXDocument().Root.Element(W.body).Add(sectPr);
                        }
                    }
                }
                else
                    FixUpSectionProperties(output);
            }
            foreach (var part in output.GetAllParts())
                if (part.Annotation<XDocument>() != null)
                    part.PutXDocument();
        }
コード例 #47
0
        /// <summary>
        /// Insert a style into a given xmlpath inside the document part
        /// </summary>
        /// <param name="xpathInsertionPoint">place where we are going to put the style</param>
        /// <param name="styleValue">name of the style</param>
        /// <param name="stylesSource">XDocument containing styles</param>
        public static OpenXmlPowerToolsDocument Insert(WmlDocument doc, string xpathInsertionPoint, string styleValue, XDocument stylesSource)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XDocument   xDocument       = document.MainDocumentPart.GetXDocument();
                    XmlDocument xmlMainDocument = new XmlDocument();
                    xmlMainDocument.Load(xDocument.CreateReader());

                    //  create the style element to add in the document, based upon the style name.
                    //  this is an example of an style element

                    //  <w:pStyle w:val="Heading1" />

                    //  so, in order to construct this, we have to know already if the style will be placed inside
                    //  a run or inside a paragraph. to know this we have to verify against the xpath, and know if
                    //  the query want to access a 'run' or a paragraph

                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlMainDocument.NameTable);
                    namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

                    XmlNodeList insertionPoints = xmlMainDocument.SelectNodes(xpathInsertionPoint, namespaceManager);

                    if (insertionPoints.Count == 0)
                    {
                        throw new ArgumentException("The xpath query did not return a valid location.");
                    }

                    foreach (XmlNode insertionPoint in insertionPoints)
                    {
                        XmlElement xmlStyle = null;

                        if (insertionPoint.LocalName == "r" || insertionPoint.LocalName == "p")
                        {
                            XmlNode propertiesElement = insertionPoint.SelectSingleNode(@"w:pPr|w:rPr", namespaceManager);

                            //if (propertiesElement != null)
                            //{
                            if (insertionPoint.Name == "w:p")
                            {
                                xmlStyle = xmlMainDocument.CreateElement("w", "pStyle", namespaceManager.LookupNamespace("w"));

                                //  retrieve the suffix from the styleAccesor class
                                xmlStyle.SetAttribute("val", namespaceManager.LookupNamespace("w"), styleValue + newStyleNameSuffix);

                                //  check if the rPr or pPr element exist, if so, then add the style xml element
                                //  inside, if not, then add a new rPr or pPr element
                                if (propertiesElement != null)
                                {
                                    //  check if there is already a style node and remove it
                                    XmlNodeList xmlStyleList = propertiesElement.SelectNodes("w:pStyle", namespaceManager);
                                    for (int i = 0; i < xmlStyleList.Count; i++)
                                    {
                                        propertiesElement.RemoveChild(xmlStyleList[i]);
                                    }
                                    propertiesElement.PrependChild(xmlStyle);
                                }
                                else
                                {
                                    propertiesElement = xmlMainDocument.CreateElement("w", "pPr", namespaceManager.LookupNamespace("w"));
                                    propertiesElement.PrependChild(xmlStyle);
                                    insertionPoint.PrependChild(propertiesElement);
                                }
                            }

                            if (insertionPoint.Name == "w:r")
                            {
                                xmlStyle = xmlMainDocument.CreateElement("w", "rStyle", namespaceManager.LookupNamespace("w"));
                                xmlStyle.SetAttribute("val", namespaceManager.LookupNamespace("w"), styleValue + newStyleNameSuffix);
                                if (propertiesElement != null)
                                {
                                    // check if there is already a style node and remove it
                                    XmlNodeList xmlStyleList = propertiesElement.SelectNodes("w:rStyle", namespaceManager);
                                    for (int i = 0; i < xmlStyleList.Count; i++)
                                    {
                                        propertiesElement.RemoveChild(xmlStyleList[i]);
                                    }
                                    propertiesElement.PrependChild(xmlStyle);
                                }
                                else
                                {
                                    propertiesElement = xmlMainDocument.CreateElement("w", "rPr", namespaceManager.LookupNamespace("w"));
                                    propertiesElement.PrependChild(xmlStyle);
                                    insertionPoint.PrependChild(propertiesElement);
                                }
                            }
                            //}
                        }
                        else
                        {
                            throw new ArgumentException("The xpath query did not return a valid location.");
                        }
                        XDocument xNewDocument = new XDocument();
                        using (XmlWriter xWriter = xNewDocument.CreateWriter())
                            xmlMainDocument.WriteTo(xWriter);
                        document.MainDocumentPart.PutXDocument(xNewDocument);

                        //  the style has been added in the main document part, but now we have to add the
                        //  style definition in the styles definitions part. the style definition need to be
                        //  extracted from the given inputStyle file.

                        //  Because a style can be linked with other styles and
                        //  can also be based on other styles,  all the complete hierarchy of styles has
                        //  to be added
                        Collection <XElement> styleHierarchy = StyleAccessor.GetStyleHierarchy(styleValue, stylesSource, newStyleNameSuffix);

                        //  open the styles file in the document
                        XDocument xmlStylesDefinitionDocument = StyleAccessor.GetStylesDocument(document);

                        XDocument xElem = new XDocument();
                        xElem.Add(xmlStylesDefinitionDocument.Root);
                        //insert the new style
                        foreach (XElement xmlStyleDefinition in styleHierarchy)
                        {
                            xElem.Root.Add(xmlStyleDefinition);
                        }
                        document.MainDocumentPart.StyleDefinitionsPart.PutXDocument(xElem);
                    }
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #48
0
        static public Commands.MatchInfo[] SearchInDocument(WmlDocument doc,
                                                            IEnumerable <string> styleSearchString, IEnumerable <string> contentSearchString,
                                                            bool isRegularExpression, bool caseInsensitive)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XNamespace w =
                        "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
                    XName r   = w + "r";
                    XName ins = w + "ins";

                    RegexOptions options;
                    Regex[]      regularExpressions = null;
                    if (isRegularExpression && contentSearchString != null)
                    {
                        if (caseInsensitive)
                        {
                            options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
                        }
                        else
                        {
                            options = RegexOptions.Compiled;
                        }
                        regularExpressions = contentSearchString
                                             .Select(s => new Regex(s, options)).ToArray();
                    }

                    var defaultStyleName = (string)document
                                           .MainDocumentPart
                                           .StyleDefinitionsPart
                                           .GetXDocument()
                                           .Root
                                           .Elements(w + "style")
                                           .Where(style =>
                                                  (string)style.Attribute(w + "type") == "paragraph" &&
                                                  (string)style.Attribute(w + "default") == "1")
                                           .First()
                                           .Attribute(w + "styleId");

                    var q1 = document
                             .MainDocumentPart
                             .GetXDocument()
                             .Root
                             .Element(w + "body")
                             .Elements()
                             .Select((p, i) =>
                    {
                        var styleNode = p
                                        .Elements(w + "pPr")
                                        .Elements(w + "pStyle")
                                        .FirstOrDefault();
                        var styleName = styleNode != null ?
                                        (string)styleNode.Attribute(w + "val") :
                                        defaultStyleName;
                        return(new
                        {
                            Element = p,
                            Index = i,
                            StyleName = styleName
                        });
                    }
                                     );

                    var q2 = q1
                             .Select(i =>
                    {
                        string text = null;
                        if (i.Element.Name == w + "p")
                        {
                            text = i.Element.Elements()
                                   .Where(z => z.Name == r || z.Name == ins)
                                   .Descendants(w + "t")
                                   .StringConcatenate(element => (string)element);
                        }
                        else
                        {
                            text = i.Element
                                   .Descendants(w + "p")
                                   .StringConcatenate(p => p
                                                      .Elements()
                                                      .Where(z => z.Name == r || z.Name == ins)
                                                      .Descendants(w + "t")
                                                      .StringConcatenate(element => (string)element),
                                                      Environment.NewLine
                                                      );
                        }

                        return(new
                        {
                            Element = i.Element,
                            StyleName = i.StyleName,
                            Index = i.Index,
                            Text = text
                        });
                    }
                                     );

                    var q3 = q2
                             .Select(i =>
                                     new Commands.MatchInfo
                    {
                        ElementNumber = i.Index + 1,
                        Content       = i.Text,
                        Style         = ContainsAnyStyles(GetAllStyleIdsAndNames(document, i.StyleName).Distinct(), styleSearchString),
                        Pattern       = ContainsAnyContent(i.Text, contentSearchString, regularExpressions, isRegularExpression, caseInsensitive),
                        IgnoreCase    = caseInsensitive
                    }
                                     )
                             .Where(i => (styleSearchString == null || i.Style != null) && (contentSearchString == null || i.Pattern != null));
                    return(q3.ToArray());
                }
        }
コード例 #49
0
        /// <summary>
        /// Removes personal information from the document.
        /// </summary>
        /// <param name="document"></param>
        public static OpenXmlPowerToolsDocument RemovePersonalInformation(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    XNamespace x = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
                    XDocument  extendedFileProperties = document.ExtendedFilePropertiesPart.GetXDocument();
                    extendedFileProperties.Elements(x + "Properties").Elements(x + "Company").Remove();
                    XElement totalTime = extendedFileProperties.Elements(x + "Properties").Elements(x + "TotalTime").FirstOrDefault();
                    if (totalTime != null)
                    {
                        totalTime.Value = "0";
                    }
                    document.ExtendedFilePropertiesPart.PutXDocument();

                    XNamespace dc = "http://purl.org/dc/elements/1.1/";
                    XNamespace cp = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
                    XDocument  coreFileProperties = document.CoreFilePropertiesPart.GetXDocument();
                    foreach (var textNode in coreFileProperties.Elements(cp + "coreProperties")
                             .Elements(dc + "creator")
                             .Nodes()
                             .OfType <XText>())
                    {
                        textNode.Value = "";
                    }
                    foreach (var textNode in coreFileProperties.Elements(cp + "coreProperties")
                             .Elements(cp + "lastModifiedBy")
                             .Nodes()
                             .OfType <XText>())
                    {
                        textNode.Value = "";
                    }
                    foreach (var textNode in coreFileProperties.Elements(cp + "coreProperties")
                             .Elements(dc + "title")
                             .Nodes()
                             .OfType <XText>())
                    {
                        textNode.Value = "";
                    }
                    XElement revision = coreFileProperties.Elements(cp + "coreProperties").Elements(cp + "revision").FirstOrDefault();
                    if (revision != null)
                    {
                        revision.Value = "1";
                    }
                    document.CoreFilePropertiesPart.PutXDocument();

                    // add w:removePersonalInformation, w:removeDateAndTime to DocumentSettingsPart
                    XNamespace w = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
                    XDocument  documentSettings = document.MainDocumentPart.DocumentSettingsPart.GetXDocument();
                    // add the new elements in the right position.  Add them after the following three elements
                    // (which may or may not exist in the xml document).
                    XElement settings   = documentSettings.Root;
                    XElement lastOfTop3 = settings.Elements()
                                          .Where(e => e.Name == w + "writeProtection" ||
                                                 e.Name == w + "view" ||
                                                 e.Name == w + "zoom")
                                          .InDocumentOrder()
                                          .LastOrDefault();
                    if (lastOfTop3 == null)
                    {
                        // none of those three exist, so add as first children of the root element
                        settings.AddFirst(
                            settings.Elements(w + "removePersonalInformation").Any() ?
                            null :
                            new XElement(w + "removePersonalInformation"),
                            settings.Elements(w + "removeDateAndTime").Any() ?
                            null :
                            new XElement(w + "removeDateAndTime")
                            );
                    }
                    else
                    {
                        // one of those three exist, so add after the last one
                        lastOfTop3.AddAfterSelf(
                            settings.Elements(w + "removePersonalInformation").Any() ?
                            null :
                            new XElement(w + "removePersonalInformation"),
                            settings.Elements(w + "removeDateAndTime").Any() ?
                            null :
                            new XElement(w + "removeDateAndTime")
                            );
                    }
                    document.MainDocumentPart.DocumentSettingsPart.PutXDocument();
                }
                return(streamDoc.GetModifiedDocument());
            }
        }
コード例 #50
0
        /// <summary>
        /// Sets the document theme
        /// </summary>
        /// <param name="theme">Theme package</param>
        public static OpenXmlPowerToolsDocument SetTheme(WmlDocument doc, OpenXmlPowerToolsDocument themeDoc)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
            {
                using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
                {
                    using (OpenXmlMemoryStreamDocument themeStream = new OpenXmlMemoryStreamDocument(themeDoc))
                    using (Package theme = themeStream.GetPackage())
                    {
                        // Gets the theme manager part
                        PackageRelationship themeManagerRelationship =
                            theme.GetRelationshipsByType(mainDocumentRelationshipType).FirstOrDefault();
                        if (themeManagerRelationship != null)
                        {
                            PackagePart themeManagerPart = theme.GetPart(themeManagerRelationship.TargetUri);

                            // Gets the theme main part
                            PackageRelationship themeRelationship =
                                themeManagerPart.GetRelationshipsByType(themeRelationshipType).FirstOrDefault();
                            if (themeRelationship != null)
                            {
                                PackagePart themePart = theme.GetPart(themeRelationship.TargetUri);
                                XDocument newThemeDocument = XDocument.Load(XmlReader.Create(themePart.GetStream(FileMode.Open, FileAccess.Read)));

                                // Removes existing theme part from document
                                if (document.MainDocumentPart.ThemePart != null)
                                    document.MainDocumentPart.DeletePart(document.MainDocumentPart.ThemePart);

                                // Creates a new theme part
                                ThemePart documentThemePart = document.MainDocumentPart.AddNewPart<ThemePart>();

                                var embeddedItems =
                                    newThemeDocument
                                    .Descendants()
                                    .Attributes(relationshipns + "embed");
                                foreach (PackageRelationship imageRelationship in themePart.GetRelationships())
                                {
                                    // Adds an image part to the theme part and stores contents inside
                                    PackagePart imagePart = theme.GetPart(imageRelationship.TargetUri);
                                    ImagePart newImagePart =
                                        documentThemePart.AddImagePart(GetImagePartType(imagePart.ContentType));
                                    newImagePart.FeedData(imagePart.GetStream(FileMode.Open, FileAccess.Read));

                                    // Updates relationship references into the theme XDocument
                                    XAttribute relationshipAttribute = embeddedItems.FirstOrDefault(e => e.Value == imageRelationship.Id);
                                    if (relationshipAttribute != null)
                                        relationshipAttribute.Value = documentThemePart.GetIdOfPart(newImagePart);
                                }
                                documentThemePart.PutXDocument(newThemeDocument);
                            }
                        }
                    }
                }
                return streamDoc.GetModifiedDocument();
            }
        }
コード例 #51
0
 public static IEnumerable<WmlDocument> SplitOnSections(WmlDocument doc)
 {
     List<TempSource> tempSourceList;
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
     {
         XDocument mainDocument = document.MainDocumentPart.GetXDocument();
         var divs = mainDocument
             .Root
             .Element(W.body)
             .Elements()
             .Select((p, i) => new
             {
                 BlockLevelContent = p,
                 Index = i,
             })
             .Rollup(new
                 {
                     BlockLevelContent = (XElement)null,
                     Index = -1,
                     Div = 0,
                 },
                 (b, p) =>
                 {
                     XElement elementBefore = b.BlockLevelContent
                         .ElementsBeforeSelfReverseDocumentOrder()
                         .FirstOrDefault();
                     if (elementBefore != null && elementBefore.Descendants(W.sectPr).Any())
                         return new
                         {
                             BlockLevelContent = b.BlockLevelContent,
                             Index = b.Index,
                             Div = p.Div + 1,
                         };
                     return new
                     {
                         BlockLevelContent = b.BlockLevelContent,
                         Index = b.Index,
                         Div = p.Div,
                     };
                 });
         var groups = divs
             .GroupAdjacent(b => b.Div);
         tempSourceList = groups
             .Select(g => new TempSource
             {
                 Start = g.First().Index,
                 Count = g.Count(),
             })
             .ToList();
         foreach (var ts in tempSourceList)
         {
             List<Source> sources = new List<Source>()
             {
                 new Source(doc, ts.Start, ts.Count, true)
             };
             WmlDocument newDoc = DocumentBuilder.BuildDocument(sources);
             newDoc = AdjustSectionBreak(newDoc);
             yield return newDoc;
         }
     }
 }
コード例 #52
0
        private static void BuildDocument(List<Source> sources, WordprocessingDocument output)
        {
            if (RelationshipMarkup == null)
                RelationshipMarkup = new Dictionary<XName, XName[]>()
                {
                    //{ button,           new [] { image }},
                    { A.blip,             new [] { R.embed, R.link }},
                    { A.hlinkClick,       new [] { R.id }},
                    { A.relIds,           new [] { R.cs, R.dm, R.lo, R.qs }},
                    //{ a14:imgLayer,     new [] { R.embed }},
                    //{ ax:ocx,           new [] { R.id }},
                    { C.chart,            new [] { R.id }},
                    { C.externalData,     new [] { R.id }},
                    { C.userShapes,       new [] { R.id }},
                    { DGM.relIds,         new [] { R.cs, R.dm, R.lo, R.qs }},
                    { O.OLEObject,        new [] { R.id }},
                    { VML.fill,           new [] { R.id }},
                    { VML.imagedata,      new [] { R.href, R.id, R.pict }},
                    { VML.stroke,         new [] { R.id }},
                    { W.altChunk,         new [] { R.id }},
                    { W.attachedTemplate, new [] { R.id }},
                    { W.control,          new [] { R.id }},
                    { W.dataSource,       new [] { R.id }},
                    { W.embedBold,        new [] { R.id }},
                    { W.embedBoldItalic,  new [] { R.id }},
                    { W.embedItalic,      new [] { R.id }},
                    { W.embedRegular,     new [] { R.id }},
                    { W.footerReference,  new [] { R.id }},
                    { W.headerReference,  new [] { R.id }},
                    { W.headerSource,     new [] { R.id }},
                    { W.hyperlink,        new [] { R.id }},
                    { W.printerSettings,  new [] { R.id }},
                    { W.recipientData,    new [] { R.id }},  // Mail merge, not required
                    { W.saveThroughXslt,  new [] { R.id }},
                    { W.sourceFileName,   new [] { R.id }},  // Framesets, not required
                    { W.src,              new [] { R.id }},  // Mail merge, not required
                    { W.subDoc,           new [] { R.id }},  // Sub documents, not required
                    //{ w14:contentPart,  new [] { R.id }},
                    { WNE.toolbarData,    new [] { R.id }},
                };


            // This list is used to eliminate duplicate images
            List<ImageData> images = new List<ImageData>();
            XDocument mainPart = output.MainDocumentPart.GetXDocument();
            mainPart.Declaration.Standalone = "yes";
            mainPart.Declaration.Encoding = "UTF-8";
            mainPart.Root.ReplaceWith(
                new XElement(W.document, NamespaceAttributes,
                    new XElement(W.body)));
            if (sources.Count > 0)
            {
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(sources[0].WmlDocument))
                using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                {
                    CopyStartingParts(doc, output, images);
                }

                int sourceNum = 0;
                foreach (Source source in sources)
                {
                    if (source.InsertId != null)
                    {
                        while (true)
                        {
                            XDocument mainXDoc = output.MainDocumentPart.GetXDocument();
                            if (!mainXDoc.Descendants(PtOpenXml.Insert).Any(d => (string)d.Attribute(PtOpenXml.Id) == source.InsertId))
                                break;
                            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(source.WmlDocument))
                            using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                            {
#if TestForUnsupportedDocuments
                                // throws exceptions if a document contains unsupported content
                                TestForUnsupportedDocument(doc, sources.IndexOf(source));
#endif
                                if (source.KeepSections && source.DiscardHeadersAndFootersInKeptSections)
                                    RemoveHeadersAndFootersFromSections(doc);
                                else if (source.KeepSections)
                                    ProcessSectionsForLinkToPreviousHeadersAndFooters(doc);

                                List<XElement> contents = doc.MainDocumentPart.GetXDocument()
                                    .Root
                                    .Element(W.body)
                                    .Elements()
                                    .Skip(source.Start)
                                    .Take(source.Count)
                                    .ToList();
                                try
                                {
                                    AppendDocument(doc, output, contents, source.KeepSections, source.InsertId, images);
                                }
                                catch (DocumentBuilderInternalException dbie)
                                {
                                    if (dbie.Message.Contains("{0}"))
                                        throw new DocumentBuilderException(string.Format(dbie.Message, sourceNum));
                                    else
                                        throw dbie;
                                }
                            }
                        }
                    }
                    else
                    {
                        using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(source.WmlDocument))
                        using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                        {
#if TestForUnsupportedDocuments
                            // throws exceptions if a document contains unsupported content
                            TestForUnsupportedDocument(doc, sources.IndexOf(source));
#endif
                            if (source.KeepSections && source.DiscardHeadersAndFootersInKeptSections)
                                RemoveHeadersAndFootersFromSections(doc);
                            else if (source.KeepSections)
                                ProcessSectionsForLinkToPreviousHeadersAndFooters(doc);

                            List<XElement> contents = doc.MainDocumentPart.GetXDocument()
                                .Root
                                .Element(W.body)
                                .Elements()
                                .Skip(source.Start)
                                .Take(source.Count)
                                .ToList();
                            try
                            {
                                AppendDocument(doc, output, contents, source.KeepSections, null, images);
                            }
                            catch (DocumentBuilderInternalException dbie)
                            {
                                if (dbie.Message.Contains("{0}"))
                                    throw new DocumentBuilderException(string.Format(dbie.Message, sourceNum));
                                else
                                    throw dbie;
                            }
                        }
                    }
                    ++sourceNum;
                }
                if (!sources.Any(s => s.KeepSections))
                {
                    using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(sources[0].WmlDocument))
                    using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument())
                    {
                        var sectPr = doc.MainDocumentPart.GetXDocument().Root.Element(W.body)
                            .Elements().Last();
                        if (sectPr.Name == W.sectPr)
                        {
                            AddSectionAndDependencies(doc, output, sectPr, images);
                            output.MainDocumentPart.GetXDocument().Root.Element(W.body).Add(sectPr);
                        }
                    }
                }
                else
                {
                    FixUpSectionProperties(output);

                    // Any sectPr elements that do not have headers and footers should take their headers and footers from the *next* section,
                    // i.e. from the running section.
                    var mxd = output.MainDocumentPart.GetXDocument();
                    var sections = mxd.Descendants(W.sectPr).Reverse().ToList();

                    CachedHeaderFooter[] cachedHeaderFooter = new[]
                    {
                        new CachedHeaderFooter() { Ref = W.headerReference, Type = "first" },
                        new CachedHeaderFooter() { Ref = W.headerReference, Type = "even" },
                        new CachedHeaderFooter() { Ref = W.headerReference, Type = "default" },
                        new CachedHeaderFooter() { Ref = W.footerReference, Type = "first" },
                        new CachedHeaderFooter() { Ref = W.footerReference, Type = "even" },
                        new CachedHeaderFooter() { Ref = W.footerReference, Type = "default" },
                    };

                    bool firstSection = true;
                    foreach (var sect in sections)
                    {
                        if (firstSection)
                        {
                            foreach (var hf in cachedHeaderFooter)
                            {
                                var referenceElement = sect.Elements(hf.Ref).FirstOrDefault(z => (string)z.Attribute(W.type) == hf.Type);
                                if (referenceElement != null)
                                    hf.CachedPartRid = (string)referenceElement.Attribute(R.id);
                            }
                            firstSection = false;
                            continue;
                        }
                        else
                        {
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.headerReference, "first");
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.headerReference, "even");
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.headerReference, "default");
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.footerReference, "first");
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.footerReference, "even");
                            CopyOrCacheHeaderOrFooter(output, cachedHeaderFooter, sect, W.footerReference, "default");
                        }

                    }
                }
            }
            foreach (var part in output.GetAllParts())
                if (part.Annotation<XDocument>() != null)
                    part.PutXDocument();
        }
コード例 #53
0
        public static IEnumerable<ValidationErrorInfo> GetOpenXmlValidationErrors(string fileName,
            string officeVersion)
        {
#if !NET35
            FileFormatVersions fileFormatVersion = FileFormatVersions.Office2013;
#else
            FileFormatVersions fileFormatVersion = FileFormatVersions.Office2010;
#endif
            try
            {
                fileFormatVersion = (FileFormatVersions)Enum.Parse(fileFormatVersion.GetType(), officeVersion);
            }
            catch (Exception)
            {
#if !NET35
                fileFormatVersion = FileFormatVersions.Office2013;
#else
                fileFormatVersion = FileFormatVersions.Office2010;
#endif
            }

            FileInfo fi = new FileInfo(fileName);
            if (Util.IsWordprocessingML(fi.Extension))
            {
                WmlDocument wml = new WmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wml))
                using (WordprocessingDocument wDoc = streamDoc.GetWordprocessingDocument())
                {
                    OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                    var errors = validator.Validate(wDoc);
                    return errors.ToList();
                }
            }
            else if (Util.IsSpreadsheetML(fi.Extension))
            {
                SmlDocument Sml = new SmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(Sml))
                using (SpreadsheetDocument wDoc = streamDoc.GetSpreadsheetDocument())
                {
                    OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                    var errors = validator.Validate(wDoc);
                    return errors.ToList();
                }
            }
            else if (Util.IsPresentationML(fi.Extension))
            {
                PmlDocument Pml = new PmlDocument(fileName);
                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(Pml))
                using (PresentationDocument wDoc = streamDoc.GetPresentationDocument())
                {
                    OpenXmlValidator validator = new OpenXmlValidator(fileFormatVersion);
                    var errors = validator.Validate(wDoc);
                    return errors.ToList();
                }
            }
            return Enumerable.Empty<ValidationErrorInfo>();
        }
コード例 #54
0
 private static WmlDocument AdjustSectionBreak(WmlDocument doc)
 {
     using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(doc))
     {
         using (WordprocessingDocument document = streamDoc.GetWordprocessingDocument())
         {
             XDocument mainXDoc = document.MainDocumentPart.GetXDocument();
             XElement lastElement = mainXDoc.Root
                 .Element(W.body)
                 .Elements()
                 .LastOrDefault();
             if (lastElement != null)
             {
                 if (lastElement.Name != W.sectPr &&
                     lastElement.Descendants(W.sectPr).Any())
                 {
                     mainXDoc.Root.Element(W.body).Add(lastElement.Descendants(W.sectPr).First());
                     lastElement.Descendants(W.sectPr).Remove();
                     if (!lastElement.Elements()
                         .Where(e => e.Name != W.pPr)
                         .Any())
                         lastElement.Remove();
                     document.MainDocumentPart.PutXDocument();
                 }
             }
         }
         return streamDoc.GetModifiedWmlDocument();
     }
 }
コード例 #55
0
        public static WmlDocument AppendParagraphToDocument(
            WmlDocument wmlDoc,
            string strParagraph,
            bool isBold,
            bool isItalic,
            bool isUnderline,
            string foreColor,
            string backColor,
            string styleName)
        {
            using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(wmlDoc))
            {
                using (WordprocessingDocument wDoc = streamDoc.GetWordprocessingDocument())
                {
                    StyleDefinitionsPart part = wDoc.MainDocumentPart.StyleDefinitionsPart;

                    Body body = wDoc.MainDocumentPart.Document.Body;

                    SectionProperties sectionProperties = body.Elements<SectionProperties>().FirstOrDefault();

                    Paragraph paragraph = new Paragraph();
                    Run run = paragraph.AppendChild(new Run());
                    RunProperties runProperties = new RunProperties();

                    if (isBold)
                        runProperties.AppendChild(new Bold());

                    if (isItalic)
                        runProperties.AppendChild(new Italic());


                    if (!string.IsNullOrEmpty(foreColor))
                    {
                        int colorValue = System.Drawing.Color.FromName(foreColor).ToArgb();
                        if (colorValue == 0)
                            throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));

                        string ColorHex = string.Format("{0:x6}", colorValue);
                        runProperties.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Color() { Val = ColorHex.Substring(2) });
                    }

                    if (isUnderline)
                        runProperties.AppendChild(new Underline() { Val = UnderlineValues.Single });

                    if (!string.IsNullOrEmpty(backColor))
                    {
                        int colorShade = System.Drawing.Color.FromName(backColor).ToArgb();
                        if (colorShade == 0)
                            throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified color {0} is unsupported, Please specify the valid color. Ex, Red, Green", foreColor));

                        string ColorShadeHex = string.Format("{0:x6}", colorShade);
                        runProperties.AppendChild(new Shading() { Fill = ColorShadeHex.Substring(2), Val = ShadingPatternValues.Clear });
                    }

                    if (!string.IsNullOrEmpty(styleName))
                    {
                        Style style = part.Styles.Elements<Style>().Where(s => s.StyleId == styleName).FirstOrDefault();
                        //if the specified style is not present in word document add it
                        if (style == null)
                        {
                            using (MemoryStream memoryStream = new MemoryStream())
                            {
                                #region Default.dotx Template has been used to get all the paragraph styles
                                string base64 =
        @"UEsDBBQABgAIAAAAIQDTMB8uXgEAACAFAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbLSUy27CMBBF
95X6D5G3VWLooqoqAos+li1S6QcYewJW/ZI9vP6+EwKoqiCRCmwiJTP33jNWxoPR2ppsCTFp70rW
L3osAye90m5Wsq/JW/7IsoTCKWG8g5JtILHR8PZmMNkESBmpXSrZHDE8cZ7kHKxIhQ/gqFL5aAXS
a5zxIOS3mAG/7/UeuPQOwWGOtQcbDl6gEguD2euaPjckEUxi2XPTWGeVTIRgtBRIdb506k9Kvkso
SLntSXMd0h01MH40oa6cDtjpPuhoolaQjUXEd2Gpi698VFx5ubCkLNptjnD6qtISDvraLUQvISU6
c2sKBBtoAiis0G7Pf5Ij4cZAujxF49sdD4gkuAbAzrkTYQXTz6tR/DLvBKkodyKmBi6PcbDuhEDa
QGie/bM5tjZtkdQ5jj4k2uj4j7H3K1urcxo4QETd/tcdEsn67Pmgvg0UqCPZfHu/DX8AAAD//wMA
UEsDBBQABgAIAAAAIQAekRq37wAAAE4CAAALAAAAX3JlbHMvLnJlbHOsksFqwzAMQO+D/YPRvVHa
wRijTi9j0NsY2QcIW0lME9vYatf+/TzY2AJd6WFHy9LTk9B6c5xGdeCUXfAallUNir0J1vlew1v7
vHgAlYW8pTF41nDiDJvm9mb9yiNJKcqDi1kVis8aBpH4iJjNwBPlKkT25acLaSIpz9RjJLOjnnFV
1/eYfjOgmTHV1mpIW3sHqj1FvoYdus4ZfgpmP7GXMy2Qj8Lesl3EVOqTuDKNain1LBpsMC8lnJFi
rAoa8LzR6nqjv6fFiYUs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UEsBAi0AFAAEAAgA0WoGQSv37OFTEgAAFa0AAA8A
AAAAAAAAAAAAAAAAOhEAAHdvcmQvc3R5bGVzLnhtbFBLAQItABQABgAIANFqBkEJ28MF3QYAAFAb
AAAVAAAAAAAAAAAAAAAAALojAAB3b3JkL3RoZW1lL3RoZW1lMS54bWxQSwECLQAUAAYACADRagZB
joxzCXABAAD0AQAAFAAAAAAAAAAAAAAAAADKKgAAd29yZC93ZWJTZXR0aW5ncy54bWxQSwUGAAAA
AAsACwDBAgAAbCwAAAAA";
                                #endregion

                                char[] base64CharArray = base64.Where(c => c != '\r' && c != '\n').ToArray();
                                byte[] byteArray = System.Convert.FromBase64CharArray(base64CharArray, 0, base64CharArray.Length);
                                memoryStream.Write(byteArray, 0, byteArray.Length);

                                using (WordprocessingDocument defaultDotx = WordprocessingDocument.Open(memoryStream, true))
                                {
                                    //Get the specified style from Default.dotx template for paragraph
                                    Style templateStyle = defaultDotx.MainDocumentPart.StyleDefinitionsPart.Styles.Elements<Style>().Where(s => s.StyleId == styleName && s.Type == StyleValues.Paragraph).FirstOrDefault();

                                    //Check if the style is proper style. Ex, Heading1, Heading2
                                    if (templateStyle == null)
                                        throw new OpenXmlPowerToolsException(String.Format("Add-DocxText: The specified style name {0} is unsupported, Please specify the valid style. Ex, Heading1, Heading2, Title", styleName));
                                    else
                                        part.Styles.Append((templateStyle.CloneNode(true)));
                                }
                            }
                        }

                        paragraph.ParagraphProperties = new ParagraphProperties(new ParagraphStyleId() { Val = styleName });
                    }

                    run.AppendChild(runProperties);
                    run.AppendChild(new Text(strParagraph));

                    if (sectionProperties != null)
                        body.InsertBefore(paragraph, sectionProperties);
                    else
                        body.AppendChild(paragraph);
                }
                return streamDoc.GetModifiedWmlDocument();
            }
        }
コード例 #56
0
        public static WmlDocument MergeComments(WmlDocument document1, WmlDocument document2,
            bool ensureLocked)
        {
            WmlDocument cDoc1 = new WmlDocument(document1);
            WmlDocument cDoc2 = new WmlDocument(document2);
            using (OpenXmlMemoryStreamDocument streamDoc1 = new OpenXmlMemoryStreamDocument(cDoc1))
            using (WordprocessingDocument doc1 = streamDoc1.GetWordprocessingDocument())
            using (OpenXmlMemoryStreamDocument streamDoc2 = new OpenXmlMemoryStreamDocument(cDoc2))
            using (WordprocessingDocument doc2 = streamDoc2.GetWordprocessingDocument())
            {
                SimplifyMarkupSettings mss = new SimplifyMarkupSettings()
                {
                    RemoveProof = true,
                    RemoveRsidInfo = true,
                    RemoveGoBackBookmark = true,
                };
                MarkupSimplifier.SimplifyMarkup(doc1, mss);
                MarkupSimplifier.SimplifyMarkup(doc2, mss);

                // If documents don't contain the same content, then don't attempt to merge comments.
                bool same = DocumentComparer.CompareDocuments(doc1, doc2);
                if (!same)
                    throw new CommentMergerDifferingContentsException(
                        "Documents do not contain the same content");

                if (doc1.MainDocumentPart.WordprocessingCommentsPart == null &&
                    doc2.MainDocumentPart.WordprocessingCommentsPart == null)
                    return new WmlDocument(document1);
                if (doc1.MainDocumentPart.WordprocessingCommentsPart != null &&
                    doc2.MainDocumentPart.WordprocessingCommentsPart == null)
                    return new WmlDocument(document1);
                if (doc1.MainDocumentPart.WordprocessingCommentsPart == null &&
                    doc2.MainDocumentPart.WordprocessingCommentsPart != null)
                    return new WmlDocument(document2);
                // If either of the documents have no comments, then return the other one.
                if (! doc1.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root
                    .Elements(W.comment).Any())
                    return new WmlDocument(document2);
                if (! doc2.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root
                    .Elements(W.comment).Any())
                    return new WmlDocument(document1);

                if (ensureLocked)
                {
                    // If either document is not locked (allowing only commenting), don't attempt to
                    // merge comments.
                    if (doc1.ExtendedFilePropertiesPart.GetXDocument().Root
                        .Element(EP.DocSecurity).Value != "8")
                        throw new CommentMergerUnlockedDocumentException(
                            "Document1 is not locked");
                    if (doc2.ExtendedFilePropertiesPart.GetXDocument().Root
                        .Element(EP.DocSecurity).Value != "8")
                        throw new CommentMergerUnlockedDocumentException(
                            "Document2 is not locked");
                }
                
                RenumberCommentsInDoc2(doc1, doc2);

                WmlDocument destDoc = new WmlDocument(document1);

                using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(destDoc))
                {
                    using (WordprocessingDocument destWDoc = streamDoc.GetWordprocessingDocument())
                    {
                        // Merge the comments part.
                        XDocument commentsPartXDoc = new XDocument(
                            new XElement(W.comments,
                                new XAttribute(XNamespace.Xmlns + "w", W.w),
                                doc1.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root.Elements(),
                                doc2.MainDocumentPart.WordprocessingCommentsPart.GetXDocument().Root.Elements()));
                        destWDoc.MainDocumentPart.WordprocessingCommentsPart.PutXDocument(commentsPartXDoc);

                        MergeCommentsInPart(doc1.MainDocumentPart, doc2.MainDocumentPart, 
                            destWDoc.MainDocumentPart, commentsPartXDoc);
                    }
                    return streamDoc.GetModifiedWmlDocument();
                }
            }
        }
コード例 #57
0
        /// <summary>
        /// Gets the document theme
        /// </summary>
        public static OpenXmlPowerToolsDocument GetTheme(WmlDocument doc)
        {
            using (OpenXmlMemoryStreamDocument sourceStreamDoc = new OpenXmlMemoryStreamDocument(doc))
                using (WordprocessingDocument document = sourceStreamDoc.GetWordprocessingDocument())
                {
                    // Loads the theme part main file
                    ThemePart theme = document.MainDocumentPart.ThemePart;
                    if (theme != null)
                    {
                        XDocument themeDocument = theme.GetXDocument();

                        // Creates the theme package (thmx file)
                        using (OpenXmlMemoryStreamDocument streamDoc = OpenXmlMemoryStreamDocument.CreatePackage())
                        {
                            using (Package themePackage = streamDoc.GetPackage())
                            {
                                // Creates the theme manager part on the new package and loads default content
                                PackagePart newThemeManagerPart = themePackage.CreatePart(new Uri("/theme/theme/themeManager.xml", UriKind.RelativeOrAbsolute), "application/vnd.openxmlformats-officedocument.themeManager+xml");
                                themePackage.CreateRelationship(newThemeManagerPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
                                using (XmlWriter xWriter = XmlWriter.Create(newThemeManagerPart.GetStream(FileMode.Create, FileAccess.Write)))
                                {
                                    CreateEmptyThemeManager().WriteTo(xWriter);
                                    xWriter.Flush();
                                }

                                // Creates the main theme part
                                PackagePart newThemePart = themePackage.CreatePart(new Uri("/theme/theme/" + theme.Uri.OriginalString.Substring(theme.Uri.OriginalString.LastIndexOf('/') + 1), UriKind.RelativeOrAbsolute), theme.ContentType);
                                newThemeManagerPart.CreateRelationship(newThemePart.Uri, TargetMode.Internal, theme.RelationshipType);

                                // Gets embeded part references
                                var embeddedItems =
                                    themeDocument
                                    .Descendants()
                                    .Attributes(relationshipns + "embed");

                                foreach (IdPartPair partId in theme.Parts)
                                {
                                    OpenXmlPart part = partId.OpenXmlPart;

                                    // Creates the new media part inside the destination package
                                    PackagePart         newPart      = themePackage.CreatePart(new Uri("/theme/media/" + part.Uri.OriginalString.Substring(part.Uri.OriginalString.LastIndexOf('/') + 1), UriKind.RelativeOrAbsolute), part.ContentType);
                                    PackageRelationship relationship =
                                        newThemePart.CreateRelationship(newPart.Uri, TargetMode.Internal, part.RelationshipType);

                                    // Copies binary content from original part to destination part
                                    Stream partStream    = part.GetStream(FileMode.Open, FileAccess.Read);
                                    Stream newPartStream = newPart.GetStream(FileMode.Create, FileAccess.Write);
                                    byte[] fileContent   = new byte[partStream.Length];
                                    partStream.Read(fileContent, 0, (int)partStream.Length);
                                    newPartStream.Write(fileContent, 0, (int)partStream.Length);
                                    newPartStream.Flush();

                                    // Replaces old embed part reference with the freshly created one
                                    XAttribute relationshipAttribute = embeddedItems.FirstOrDefault(e => e.Value == theme.GetIdOfPart(part));
                                    if (relationshipAttribute != null)
                                    {
                                        relationshipAttribute.Value = relationship.Id;
                                    }
                                }

                                // Writes the updated theme XDocument into the destination package
                                using (XmlWriter newThemeWriter = XmlWriter.Create(newThemePart.GetStream(FileMode.Create, FileAccess.Write)))
                                    themeDocument.WriteTo(newThemeWriter);
                            }
                            return(streamDoc.GetModifiedDocument());
                        }
                    }
                    return(null);
                }
        }