Пример #1
0
        /// <summary>
        /// Created a new instance of the PresentationDocument class from the specified file.
        /// </summary>
        /// <param name="path">The path and file name of the target PresentationDocument.</param>
        /// <param name="type">The type of the PresentationDocument.</param>
        /// <param name="autoSave">Whether to auto save the created document.</param>
        /// <returns>A new instance of PresentationDocument.</returns>
        /// <exception cref="ArgumentNullException">Thrown when "path" is null reference.</exception>
        public static PresentationDocument Create(string path, PresentationDocumentType type, bool autoSave)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(path);
            }

            var doc = new PresentationDocument
            {
                DocumentType = type,
                OpenSettings = new OpenSettings {
                    AutoSave = autoSave
                },
                MainPartContentType = MainPartContentTypes[type],
            };

            doc.CreateCore(path);

            return(doc);
        }
Пример #2
0
        /// <summary>
        /// Creates a new instance of the PresentationDocument class from the spcified package.
        /// </summary>
        /// <param name="package">The specified OpenXml package.</param>
        /// <param name="openSettings">The advanced settings for opening a document.</param>
        /// <returns>A new instance of PresentationDocument.</returns>
        /// <exception cref="ArgumentNullException">Thrown when package is a null reference.</exception>
        /// <exception cref="OpenXmlPackageException">Thrown when package is not opened with read access.</exception>
        /// <exception cref="OpenXmlPackageException">Thrown when the package is not a valid Open XML document.</exception>
        /// <exception cref="ArgumentException">Thrown when specified to process the markup compatibility but the given target FileFormatVersion is incorrect.</exception>
        public static PresentationDocument Open(Package package, OpenSettings openSettings)
        {
            if (openSettings.MarkupCompatibilityProcessSettings.ProcessMode != MarkupCompatibilityProcessMode.NoProcess &&
                !openSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions.Any())
            {
                throw new ArgumentException(ExceptionMessages.InvalidMCMode);
            }
            PresentationDocument doc = new PresentationDocument();

            doc.OpenSettings          = new OpenSettings();
            doc.OpenSettings.AutoSave = openSettings.AutoSave;
            doc.OpenSettings.MarkupCompatibilityProcessSettings.ProcessMode = openSettings.MarkupCompatibilityProcessSettings.ProcessMode;
            doc.OpenSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions = openSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions;
            doc.MaxCharactersInPart = openSettings.MaxCharactersInPart;
            doc.OpenCore(package);
            if (MainPartContentTypes[doc.DocumentType] != doc.MainPartContentType)
            {
                doc.UpdateDocumentTypeFromContentType();
            }
            return(doc);
        }
Пример #3
0
        /// <summary>
        /// Creates an editable PresentationDocument from a template, opened on
        /// a MemoryStream with expandable capacity.
        /// </summary>
        /// <param name="path">The path and file name of the template.</param>
        /// <returns>The new PresentationDocument based on the template.</returns>
        public static PresentationDocument CreateFromTemplate(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            // Check extensions as the template must have a valid Word Open XML extension.
            string extension = Path.GetExtension(path);

            if (extension != ".pptx" && extension != ".pptm" && extension != ".potx" && extension != ".potm")
            {
                throw new ArgumentException("Illegal template file: " + path, nameof(path));
            }

            using (PresentationDocument template = PresentationDocument.Open(path, false))
            {
                // We've opened the template in read-only mode to let multiple processes or
                // threads open it without running into problems.
                PresentationDocument document = (PresentationDocument)template.Clone();

                // If the template is a document rather than a template, we are done.
                if (extension == ".xlsx" || extension == ".xlsm")
                {
                    return(document);
                }

                // Otherwise, we'll have to do some more work.
                document.ChangeDocumentType(PresentationDocumentType.Presentation);

                // We are done, so save and return.
                // TODO: Check whether it would be safe to return without saving.
                document.Save();
                return(document);
            }
        }
Пример #4
0
 /// <summary>
 /// Creates a new instance of OpenXmlPackage on the specified instance
 /// of Package.
 /// </summary>
 /// <param name="package">The specified instance of Package.</param>
 /// <returns>A new instance of OpenXmlPackage.</returns>
 protected override OpenXmlPackage CreateClone(Package package)
 {
     return(PresentationDocument.Create(package, DocumentType, OpenSettings.AutoSave));
 }
Пример #5
0
 /// <summary>
 /// Opens the cloned OpenXml package on the given file.
 /// </summary>
 /// <param name="path">The path and file name of the target OpenXml package.</param>
 /// <param name="isEditable">In ReadWrite mode. False for Read only mode.</param>
 /// <param name="openSettings">The advanced settings for opening a document.</param>
 /// <returns>A new instance of OpenXmlPackage.</returns>
 protected override OpenXmlPackage OpenClone(string path, bool isEditable, OpenSettings openSettings)
 {
     return(PresentationDocument.Open(path, isEditable, openSettings));
 }
Пример #6
0
 /// <summary>
 /// Creates a new instance of the PresentationDocument class from the spcified package.
 /// </summary>
 /// <param name="package">The specified OpenXml package.</param>
 /// <returns>A new instance of PresentationDocument.</returns>
 /// <exception cref="ArgumentNullException">Thrown when "package" is null reference.</exception>
 /// <exception cref="IOException">Thrown when "package" is not opened with Read (ReadWrite) access.</exception>
 /// <exception cref="OpenXmlPackageException">Thrown when the package is not valid Open XML PresentationDocument.</exception>
 public static PresentationDocument Open(System.IO.Packaging.Package package)
 {
     return(PresentationDocument.Open(package, new OpenSettings()));
 }
Пример #7
0
 /// <summary>
 /// Creates a new instance of the PresentationDocument class from the IO stream.
 /// </summary>
 /// <param name="stream">The IO stream on which to open the PresentationDocument.</param>
 /// <param name="isEditable">In ReadWrite mode. False for Read only mode.</param>
 /// <returns>A new instance of PresentationDocument.</returns>
 /// <exception cref="ArgumentNullException">Thrown when "stream" is null reference.</exception>
 /// <exception cref="IOException">Thrown when "stream" is not opened with Read (ReadWrite) access.</exception>
 /// <exception cref="OpenXmlPackageException">Thrown when the package is not valid Open XML PresentationDocument.</exception>
 public static PresentationDocument Open(System.IO.Stream stream, bool isEditable)
 {
     return(PresentationDocument.Open(stream, isEditable, new OpenSettings()));
 }
Пример #8
0
 /// <summary>
 /// Creates a new instance of the PresentationDocument class from the specified file.
 /// </summary>
 /// <param name="path">The path and file name of the target PresentationDocument.</param>
 /// <param name="isEditable">In ReadWrite mode. False for Read only mode.</param>
 /// <returns>A new instance of PresentationDocument.</returns>
 /// <exception cref="ArgumentNullException">Thrown when "path" is null reference.</exception>
 /// <exception cref="OpenXmlPackageException">Thrown when the package is not valid Open XML PresentationDocument.</exception>
 public static PresentationDocument Open(string path, bool isEditable)
 {
     return(PresentationDocument.Open(path, isEditable, new OpenSettings()));
 }
Пример #9
0
 // The New API
 public static PresentationDocument Open(DocumentFormat.OpenXml.Packaging.IPackage package)
 {
     return(PresentationDocument.Open(package));
 }
Пример #10
0
        public static PresentationDocument Open(System.IO.Packaging.Package package)
        {
            IPackage packageAdapt = new PackageAdapt(package);

            return(PresentationDocument.Open(packageAdapt));
        }