Exemplo n.º 1
0
        /// <summary>
        /// Creates a Wordprocessing document containing all comments form a given Wordprocessing document
        /// </summary>
        /// <param name="contents">Comment contents</param>
        private PTWordprocessingDocument CreateCommentDocument(IEnumerable <XElement> contents)
        {
            string tempPath = Path.GetTempFileName();
            PTWordprocessingDocument doc = new PTWordprocessingDocument(tempPath);

            doc.InnerContent.SetContent(contents);
            return(doc);
        }
Exemplo n.º 2
0
        /// <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 void InsertFormat(PTWordprocessingDocument document, string xpathInsertionPoint, string content)
        {
            XDocument   xDocument       = parentDocument.GetXDocument(document.Document.MainDocumentPart);
            XmlDocument xmlMainDocument = OpenXmlDocument.LoadXmlDocumentFromXDocument(xDocument);

            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 Exception("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 Exception("Specified xpath query result is not a valid location to place a formatting markup");
                }
            }
            OpenXmlDocument.SaveXmlDocumentIntoXDocument(xmlMainDocument, xDocument);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="document">Document to process</param>
 public TOAAccessor(PTWordprocessingDocument document)
 {
     this.parentDocument = document;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public HeaderAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public StyleAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public PictureAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
     parentPart     = document.Document.MainDocumentPart;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public CustomXmlAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public WatermarkAccesor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public BackgroundAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 public ContentFormatAccessor(PTWordprocessingDocument document)
 {
     parentDocument = document;
 }