Пример #1
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));
 }
Пример #2
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(SpreadsheetDocument.Open(path, isEditable, openSettings));
 }
        /// <summary>
        /// Creates a new instance of the WordprocessingDocument class from the specified 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 WordprocessingDocument.</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 WordprocessingDocument Open(System.IO.Packaging.Package package, OpenSettings openSettings)
        {
            if (openSettings.MarkupCompatibilityProcessSettings.ProcessMode != MarkupCompatibilityProcessMode.NoProcess &&
                !openSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions.Any())
            {
                throw new ArgumentException(ExceptionMessages.InvalidMCMode);
            }

            WordprocessingDocument doc = new WordprocessingDocument();

            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);
        }
Пример #4
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(WordprocessingDocument.Open(path, isEditable, openSettings));
 }
        /// <summary>
        /// Creates a new instance of the SpreadsheetDocument class from the IO stream.
        /// </summary>
        /// <param name="stream">The IO stream on which to open the SpreadsheetDocument.</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 SpreadsheetDocument.</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 SpreadsheetDocument.</exception>
        /// <exception cref="ArgumentException">Thrown when specified to process the markup compatibility but the given target FileFormatVersion is incorrect.</exception>
        public static SpreadsheetDocument Open(System.IO.Stream stream, bool isEditable, OpenSettings openSettings)
        {
            if (openSettings.MarkupCompatibilityProcessSettings.ProcessMode != MarkupCompatibilityProcessMode.NoProcess &&
                !openSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions.Any())
            {
                throw new ArgumentException(ExceptionMessages.InvalidMCMode);
            }
            SpreadsheetDocument doc = new SpreadsheetDocument();

            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(stream, isEditable);
            if (MainPartContentTypes[doc.DocumentType] != doc.MainPartContentType)
            {
                doc.UpdateDocumentTypeFromContentType();
            }
            return(doc);
        }