/// <summary>
        /// Begins a PowerTools Block by (1) removing annotations and, unless the package was
        /// opened in read-only mode, (2) saving the package.
        /// </summary>
        /// <remarks>
        /// Removes <see cref="XDocument" /> and <see cref="XmlNamespaceManager" /> instances
        /// added by <see cref="PtOpenXmlExtensions.GetXDocument(OpenXmlPart)" />,
        /// <see cref="PtOpenXmlExtensions.GetXDocument(OpenXmlPart, out XmlNamespaceManager)" />,
        /// <see cref="PtOpenXmlExtensions.PutXDocument(OpenXmlPart)" />,
        /// <see cref="PtOpenXmlExtensions.PutXDocument(OpenXmlPart, XDocument)" />, and
        /// <see cref="PtOpenXmlExtensions.PutXDocumentWithFormatting(OpenXmlPart)" />.
        /// methods.
        /// </remarks>
        /// <param name="package">
        /// A <see cref="WordprocessingDocument" />, <see cref="SpreadsheetDocument" />,
        /// or <see cref="PresentationDocument" />.
        /// </param>
        public static void BeginPowerToolsBlock(this OpenXmlPackage package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            package.RemovePowerToolsAnnotations();
            package.Save();
        }
Exemple #2
0
 public void Save()
 {
     mainDocumentPart.Document.Save();
     wordProcessingDocument.Save();
     //rewriting whole file
     using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
     {
         using (OpenXmlPackage docfile = wordProcessingDocument.Clone(stream))
         {
             docfile.Save();
         }
     }//stream is not automaticaly closed when document closed (when using Clone)
 }