コード例 #1
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="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 "package" is null reference.</exception>
        /// <exception cref="IOException">Thrown when "package" is not opened with Write access.</exception>
        public static PresentationDocument Create(Package package, PresentationDocumentType type, bool autoSave)
        {
            PresentationDocument doc = new PresentationDocument();

            doc.DocumentType          = type;
            doc.OpenSettings          = new OpenSettings();
            doc.OpenSettings.AutoSave = autoSave;
            doc.MainPartContentType   = MainPartContentTypes[type];
            doc.CreateCore(package);
            return(doc);
        }
コード例 #2
0
        private void UpdateDocumentTypeFromContentType()
        {
            if (MainPartContentType == null)
            {
                throw new InvalidOperationException();
            }

            foreach (KeyValuePair <PresentationDocumentType, string> types in MainPartContentTypes)
            {
                if (types.Value == MainPartContentType)
                {
                    DocumentType = types.Key;
                }
            }
        }
コード例 #3
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);
            }
            PresentationDocument doc = new PresentationDocument();

            doc.DocumentType          = type;
            doc.OpenSettings          = new OpenSettings();
            doc.OpenSettings.AutoSave = autoSave;
            doc.MainPartContentType   = MainPartContentTypes[type];
            doc.CreateCore(path);
            return(doc);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new instance of the PresentationDocument class from the specified package.
        /// </summary>
        /// <param name="package">The specified OpenXml package.</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 "package" is null reference.</exception>
        /// <exception cref="IOException">Thrown when "package" is not opened with Write access.</exception>
        public static PresentationDocument Create(Package package, PresentationDocumentType type, bool autoSave)
        {
            var doc = new PresentationDocument
            {
                DocumentType = type,
                OpenSettings = new OpenSettings {
                    AutoSave = autoSave
                },
                MainPartContentType = MainPartContentTypes[type],
            };

            doc.CreateCore(package);

            return(doc);
        }
コード例 #5
0
        /// <summary>
        /// Changes the document type.
        /// </summary>
        /// <param name="newType">The new type of the document.</param>
        /// <remarks>The PresentationPart will be changed.</remarks>
        public void ChangeDocumentType(PresentationDocumentType newType)
        {
            ThrowIfObjectDisposed();

            if (newType == DocumentType)
            {
                // same type, just return
                return;
            }

            if (FileOpenAccess == FileAccess.Read)
            {
                throw new IOException(ExceptionMessages.PackageAccessModeIsReadonly);
            }

            PresentationDocumentType oldType = DocumentType;

            DocumentType        = newType;
            MainPartContentType = MainPartContentTypes[newType];

            if (PresentationPart == null)
            {
                return;
            }

            try
            {
                ChangeDocumentTypeInternal <PresentationPart>();
            }
            catch (OpenXmlPackageException e)
            {
                if (e.Message == ExceptionMessages.CannotChangeDocumentType)
                {
                    DocumentType        = oldType;
                    MainPartContentType = MainPartContentTypes[oldType];
                }

                throw;
            }
        }
コード例 #6
0
 /// <summary>
 /// Created a new instance of the PresentationDocument class from the spcified package.
 /// </summary>
 /// <param name="package">The specified OpenXml package.</param>
 /// <param name="type">The type of the PresentationDocument.</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 Write access.</exception>
 public static PresentationDocument Create(Package package, PresentationDocumentType type)
 {
     return(Create(package, type, true));
 }
コード例 #7
0
 /// <summary>
 /// Created a new instance of the PresentationDocument class from the IO stream.
 /// </summary>
 /// <param name="stream">The IO stream on which to create the PresentationDocument.</param>
 /// <param name="type">The type of the PresentationDocument.</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 Write access.</exception>
 public static PresentationDocument Create(Stream stream, PresentationDocumentType type)
 {
     return(Create(stream, type, true));
 }
コード例 #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="type">The type of the PresentationDocument.</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)
 {
     return(Create(path, type, true));
 }