예제 #1
0
        /// <summary>
        /// Save this workbook to the given stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="compress">Use compression? (Smaller files/higher CPU Usage)</param>
        /// <exception cref="InvalidOperationException">Thrown if there are no <see cref="Worksheet">sheets</see> in the workbook.</exception>
        public void Save(Stream stream, bool compress = true)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanWrite)
            {
                throw new InvalidOperationException("Stream to save to is not writeable.");
            }

            if (stream.CanSeek)
            {
                XlsxWriter.Save(this, stream, compress);
            }
            else
            {
                // ZipArchive needs a seekable stream. If a stream is not seekable (e.g., HttpContext.Response.OutputStream), wrap it in a MemoryStream instead.
                // TODO: Can we guess the required capacity?
                using (var ms = new MemoryStream())
                {
                    XlsxWriter.Save(this, ms, compress);
                    ms.CopyTo(stream);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Save this workbook to the given stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="compress">Use compression? (Smaller files/higher CPU Usage)</param>
        /// <exception cref="InvalidOperationException">Thrown if there are no <see cref="Worksheet">sheets</see> in the workbook.</exception>
        public void Save(Stream stream, bool compress = true)
        {
            if (stream == null || !stream.CanWrite || !stream.CanSeek)
            {
                throw new InvalidOperationException("Stream to save to must be writeable and seekable.");
            }

            XlsxWriter.Save(this, stream, compress);
        }
예제 #3
0
        /// <summary>
        /// Saves the workbook with the defined name
        /// </summary>
        /// <param name="filename">filename of the saved workbook</param>
        /// <exception cref="Exceptions.IOException">Throws IOException in case of an error</exception>
        /// <exception cref="RangeException">Throws an RangeException if the start or end address of a handled cell range was out of range</exception>
        /// <exception cref="Exceptions.FormatException">Throws a FormatException if a handled date cannot be translated to (Excel internal) OADate</exception>
        /// <exception cref="StyleException">Throws an StyleException if one of the styles of the workbook cannot be referenced or is null</exception>
        public void SaveAs(string filename)
        {
            string backup = filename;

            this.filename = filename;
            XlsxWriter l = new XlsxWriter(this);

            l.Save();
            this.filename = backup;
        }
예제 #4
0
 private void SaveToOffice12File(Stream stream, string password, ExcelFileType workbookType)
 {
     if (stream != null)
     {
         bool flag = false;
         if (((password != null) && (password.Length > 0)) && (password.Length < 0x100))
         {
             flag = true;
         }
         this._exportedExcelVersion = ExcelVersion.Excel2007;
         XlsxWriter writer = new XlsxWriter(this._excelWriter, this._documentInfo, workbookType);
         if (flag)
         {
             stream = (Stream) new MemoryStream();
         }
         writer.Save(stream);
     }
 }
예제 #5
0
        /// <summary>
        /// Saves the workbook
        /// </summary>
        /// <exception cref="Exceptions.IOException">Throws IOException in case of an error</exception>
        /// <exception cref="RangeException">Throws an RangeException if the start or end address of a handled cell range was out of range</exception>
        /// <exception cref="Exceptions.FormatException">Throws a FormatException if a handled date cannot be translated to (Excel internal) OADate</exception>
        /// <exception cref="StyleException">Throws an StyleException if one of the styles of the workbook cannot be referenced or is null</exception>
        public void Save()
        {
            XlsxWriter l = new XlsxWriter(this);

            l.Save();
        }
예제 #6
0
 /// <summary>
 /// Save this workbook to the given stream
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="compress">Use compression? (Smaller files/higher CPU Usage)</param>
 /// <exception cref="InvalidOperationException">Thrown if there are no <see cref="Worksheet">sheets</see> in the workbook.</exception>
 public void Save(Stream stream, bool compress = true)
 {
     XlsxWriter.Save(this, stream, compress);
 }
예제 #7
0
 /// <summary>
 /// Save this workbook to the given stream
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="compressionLevel">How much should content in a workbook be compressed? (Higher CPU Usage)</param>
 /// <exception cref="InvalidOperationException">Thrown if there are no <see cref="Worksheet">sheets</see> in the workbook.</exception>
 public void Save(Stream stream, CompressionLevel compressionLevel)
 {
     XlsxWriter.Save(this, compressionLevel, stream);
 }