Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance based on the specified System.IO.Stream.
        /// </summary>
        /// <param name="stream">The System.IO.Stream to open the spreadsheet from.</param>
        /// <returns>New instance of ExcelOpenXmlDocument class.</returns>
        public static ExcelOpenXmlDocument Load(Stream stream)
        {
            var excel = new ExcelOpenXmlDocument
            {
                Document = SpreadsheetDocument.Open(stream, true)
            };

            excel.Intialize();
            return(excel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new instance based on the specified existing spreadsheet file.
        /// </summary>
        /// <param name="fileName">The location of the existing spreadsheet document.</param>
        /// <returns>New instance of ExcelOpenXmlDocument class.</returns>
        public static ExcelOpenXmlDocument Load(string filePath)
        {
            var excel = new ExcelOpenXmlDocument
            {
                Document = SpreadsheetDocument.Open(filePath, true)
            };

            excel.Intialize();
            return(excel);
        }
Exemplo n.º 3
0
        /// <summary>
        /// <para>Creates a new spreadsheet in the specified System.IO.Stream and returns a new instance</para>
        /// <para>of this class.</para>
        /// </summary>
        /// <param name="stream">The System.IO.Stream to create the spreadsheet in.</param>
        /// <returns>New instance of ExcelOpenXmlDocument class.</returns>
        public static ExcelOpenXmlDocument Create(Stream stream)
        {
            var excel = new ExcelOpenXmlDocument();

            excel.Document = SpreadsheetDocument.Create(
                stream,
                SpreadsheetDocumentType.Workbook);

            PopulateNewDocument(excel);
            excel.Intialize();

            return(excel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new spreadsheet based on the specified spreadsheet template.
        /// </summary>
        /// <param name="filePath">The location of the new spreadsheet document.</param>
        /// <param name="templateFilePath">The location to the template spreadsheet.</param>
        /// /// <returns>New instance of ExcelOpenXmlDocument class.</returns>
        public static ExcelOpenXmlDocument Create(string filePath, string templateFilePath)
        {
            if (!File.Exists(templateFilePath))
            {
                throw new FileNotFoundException("Could not find specified Excel template.");
            }

            File.Copy(templateFilePath, filePath);

            var excel = new ExcelOpenXmlDocument
            {
                Document = SpreadsheetDocument.Open(filePath, true)
            };

            excel.Intialize();
            return(excel);
        }