예제 #1
0
        /// <summary>
        /// Creates a new instance of the SpreadsheetDocument class from the specified package.
        /// </summary>
        /// <param name="package">The specified OpenXml package.</param>
        /// <param name="type">The type of the SpreadsheetDocument.</param>
        /// <param name="autoSave">Whether to auto save the created document.</param>
        /// <returns>A new instance of SpreadsheetDocument.</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 SpreadsheetDocument Create(Package package, SpreadsheetDocumentType type, bool autoSave)
        {
            SpreadsheetDocument doc = new SpreadsheetDocument();

            doc.DocumentType          = type;
            doc.OpenSettings          = new OpenSettings();
            doc.OpenSettings.AutoSave = autoSave;
            doc.MainPartContentType   = MainPartContentTypes[type];
            doc.CreateCore(package);
            return(doc);
        }
예제 #2
0
        public static SpreadsheetDocument Create(Package package, SpreadsheetDocumentType type, bool autoSave)
        {
            var doc = new SpreadsheetDocument
            {
                DocumentType = type,
                OpenSettings = new OpenSettings {
                    AutoSave = autoSave
                },
                MainPartContentType = MainPartContentTypes[type],
            };

            doc.CreateCore(package);

            return(doc);
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of the SpreadsheetDocument class from the specified file.
        /// </summary>
        /// <param name="path">The path and file name of the target SpreadsheetDocument.</param>
        /// <param name="type">The type of the SpreadsheetDocument.</param>
        /// <param name="autoSave">Whether to auto save the created document.</param>
        /// <returns>A new instance of SpreadsheetDocument.</returns>
        /// <exception cref="ArgumentNullException">Thrown when "path" is null reference.</exception>
        public static SpreadsheetDocument Create(string path, SpreadsheetDocumentType type, bool autoSave)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            SpreadsheetDocument doc = new SpreadsheetDocument();

            doc.DocumentType          = type;
            doc.OpenSettings          = new OpenSettings();
            doc.OpenSettings.AutoSave = autoSave;
            doc.MainPartContentType   = MainPartContentTypes[type];
            doc.CreateCore(path);
            return(doc);
        }