/// <summary> /// Creates a new instance of the WordprocessingDocument class from the spcified package. /// </summary> /// <param name="package">The specified OpenXml package</param> /// <param name="type">The type of the WordprocessingDocument.</param> /// <param name="autoSave">Whether to auto save the created document.</param> /// <returns>A new instance of WordprocessingDocument.</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 WordprocessingDocument Create(Package package, WordprocessingDocumentType type, bool autoSave) { WordprocessingDocument doc = new WordprocessingDocument(); doc.DocumentType = type; doc.OpenSettings = new OpenSettings(); doc.OpenSettings.AutoSave = autoSave; doc.MainPartContentType = MainPartContentTypes[type]; doc.CreateCore(package); return(doc); }
/// <summary> /// Creates a new instance of the WordprocessingDocument class from the specified file. /// </summary> /// <param name="path">The path and file name of the target WordprocessingDocument.</param> /// <param name="type">The type of the WordprocessingDocument.</param> /// <param name="autoSave">Whether to auto save the created document.</param> /// <returns>A new instance of WordprocessingDocument.</returns> /// <exception cref="ArgumentNullException">Thrown when "path" is null reference.</exception> public static WordprocessingDocument Create(string path, WordprocessingDocumentType type, bool autoSave) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } WordprocessingDocument doc = new WordprocessingDocument(); doc.DocumentType = type; doc.OpenSettings = new OpenSettings(); doc.OpenSettings.AutoSave = autoSave; doc.MainPartContentType = MainPartContentTypes[type]; doc.CreateCore(path); return(doc); }
public static WordprocessingDocument Create(Package package, WordprocessingDocumentType type, bool autoSave) { var doc = new WordprocessingDocument { DocumentType = type, OpenSettings = new OpenSettings { AutoSave = autoSave }, MainPartContentType = MainPartContentTypes[type], }; doc.CreateCore(package); return(doc); }