/// <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); }
private void UpdateDocumentTypeFromContentType() { if (MainPartContentType == null) { throw new InvalidOperationException(); } foreach (KeyValuePair <PresentationDocumentType, string> types in MainPartContentTypes) { if (types.Value == MainPartContentType) { DocumentType = types.Key; } } }
/// <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); }
/// <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); }
/// <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; } }
/// <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)); }
/// <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)); }
/// <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)); }