/// <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); } }
/// <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)); }
/// <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())); }
/// <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())); }
/// <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())); }
// The New API public static PresentationDocument Open(DocumentFormat.OpenXml.Packaging.IPackage package) { return(PresentationDocument.Open(package)); }
public static PresentationDocument Open(System.IO.Packaging.Package package) { IPackage packageAdapt = new PackageAdapt(package); return(PresentationDocument.Open(packageAdapt)); }