/// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="document">Document to perform operations on</param>
 /// <param name="fullName">Full path name of document</param>
 public PTWordprocessingDocument(OpenXmlSDK.WordprocessingDocument document, string fullName)
     : base()
 {
     Document         = document;
     FullName         = fullName;
     InnerContent     = new WordprocessingDocumentManager(this);
     Comments         = new CommentAccessor(this);
     Changes          = new ChangeAccessor(this);
     Headers          = new HeaderAccessor(this);
     Footer           = new FooterAccessor(this);
     Setting          = new SettingAccessor(this);
     CustomXml        = new CustomXmlAccessor(this);
     Background       = new BackgroundAccessor(this);
     Style            = new StyleAccessor(this);
     Format           = new ContentFormatAccessor(this);
     Picture          = new PictureAccessor(this);
     Watermark        = new WatermarkAccesor(this);
     Theme            = new ThemeAccessor(this);
     TOC              = new TOCAccessor(this);
     TOF              = new TOFAccessor(this);
     TOA              = new TOAAccessor(this);
     Index            = new IndexAccessor(this);
     CoreProperties   = new CorePropertiesAccesor(this);
     CustomProperties = new CustomPropertiesAccesor(this);
 }
Esempio n. 2
0
 protected override void ProcessRecord()
 {
     if (xmlPath != null)
     {
         customData = XDocument.Load(xmlPath);
         if (partName == null)
         {
             partName = System.IO.Path.GetFileName(xmlPath);
         }
     }
     foreach (var document in AllDocuments("Set-OpenXmlCustomXmlData"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             OutputDocument(CustomXmlAccessor.SetDocument((WmlDocument)document, customData, partName));
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="filePath">Path of document to load</param>
        /// <param name="createNew">Whether create a new document or load contents from existing one</param>
        public PTWordprocessingDocument(string filePath, bool createNew)
            : base()
        {
            try
            {
                if (createNew)
                {
                    Document = OpenXmlSDK.WordprocessingDocument.Create(filePath, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
                }
                else
                {
                    Document = OpenXmlSDK.WordprocessingDocument.Open(filePath, true);
                }
                FullName = filePath;

                InnerContent = new WordprocessingDocumentManager(this);
                Comments     = new CommentAccessor(this);
                Changes      = new ChangeAccessor(this);
                Headers      = new HeaderAccessor(this);
                Footer       = new FooterAccessor(this);
                Setting      = new SettingAccessor(this);
                CustomXml    = new CustomXmlAccessor(this);
                Background   = new BackgroundAccessor(this);
                Style        = new StyleAccessor(this);
                Format       = new ContentFormatAccessor(this);
                Picture      = new PictureAccessor(this);
                Watermark    = new WatermarkAccesor(this);
                Theme        = new ThemeAccessor(this);
                TOC          = new TOCAccessor(this);
                TOF          = new TOFAccessor(this);
                TOA          = new TOAAccessor(this);
                Index        = new IndexAccessor(this);
            }
            catch (OpenXmlSDK.OpenXmlPackageException ope)
            {
                throw new Exception("Bad formed OpenXml package", ope);
            }
            catch (FileFormatException ffe) {
                throw new Exception("File contains corrupted data", ffe);
            }
            catch (Exception)
            {
                throw;
            }
        }
 protected override void ProcessRecord()
 {
     foreach (var document in AllDocuments("Get-OpenXmlCustomXmlData"))
     {
         try
         {
             if (!(document is WmlDocument))
             {
                 throw new PowerToolsDocumentException("Not a wordprocessing document.");
             }
             WriteObject(CustomXmlAccessor.Find((WmlDocument)document, xmlPartName), true);
         }
         catch (Exception e)
         {
             WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document));
         }
     }
 }
 /// <summary>
 /// WordprocessingDocument (Constructor)
 /// </summary>
 public PTWordprocessingDocument()
     : base()
 {
     memoryStream = new MemoryStream();
     Document     = OpenXmlSDK.WordprocessingDocument.Create(memoryStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
     InnerContent = new WordprocessingDocumentManager(this);
     Comments     = new CommentAccessor(this);
     Changes      = new ChangeAccessor(this);
     Headers      = new HeaderAccessor(this);
     Footer       = new FooterAccessor(this);
     Setting      = new SettingAccessor(this);
     CustomXml    = new CustomXmlAccessor(this);
     Background   = new BackgroundAccessor(this);
     Style        = new StyleAccessor(this);
     Format       = new ContentFormatAccessor(this);
     Picture      = new PictureAccessor(this);
     Watermark    = new WatermarkAccesor(this);
     Theme        = new ThemeAccessor(this);
     TOC          = new TOCAccessor(this);
     TOF          = new TOFAccessor(this);
 }