Ejemplo n.º 1
0
        /// <summary>
        /// Save the Xlsx Package to a new Stream (that the caller owns and has to dispose)
        /// </summary>
        /// <returns></returns>
        internal void SaveToStream(Stream outputStream, bool compress)
        {
            if (outputStream == null || !outputStream.CanWrite || !outputStream.CanSeek)
            {
                throw new InvalidOperationException("Stream to save to must be writeable and seekable.");
            }

            using (var pkg = new ZipPackage(outputStream, compress))
            {
                WriteInfoXmlFile(pkg);

                foreach (var file in XmlFiles)
                {
                    pkg.WriteXmlFile(file);

                    var relations = Relationships.Where(r => r.Target == file);
                    foreach (var rel in relations)
                    {
                        pkg.AddRelationship(rel);
                    }
                }

                if (WorkbookRelationships.Count > 0)
                {
                    pkg.WriteXmlFile(WorkbookRelsXml());
                }
            }
            outputStream.Seek(0, SeekOrigin.Begin);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save the Xlsx Package to a new Stream (that the caller owns and has to dispose)
        /// </summary>
        /// <returns></returns>
        internal void SaveToStream(Stream outputStream, bool compress)
        {
            using (var pkg = new ZipPackage(outputStream, compress))
            {
                WriteInfoXmlFile(pkg);

                foreach (var file in XmlFiles)
                {
                    pkg.WriteXmlFile(file);

                    var relations = Relationships.Where(r => r.Target == file);
                    foreach (var rel in relations)
                    {
                        pkg.AddRelationship(rel);
                    }
                }

                if (WorkbookRelationships.Count > 0)
                {
                    pkg.WriteXmlFile(WorkbookRelsXml());
                }
            }
            outputStream.Seek(0, SeekOrigin.Begin);
        }