コード例 #1
0
ファイル: ZipPackage.cs プロジェクト: mmsgau/EPPlus-1
        internal void Save(Stream stream)
        {
            var             enc = Encoding.UTF8;
            ZipOutputStream os  = new ZipOutputStream(stream, true);

            os.EnableZip64      = Zip64Option.AsNecessary;
            os.CompressionLevel = (OfficeOpenXml.Packaging.Ionic.Zlib.CompressionLevel)_compression;

            /**** ContentType****/
            var entry = os.PutNextEntry("[Content_Types].xml");

            byte[] b = enc.GetBytes(GetContentTypeXml());
            os.Write(b, 0, b.Length);
            /**** Top Rels ****/
            _rels.WriteZip(os, $"_rels/.rels");
            ZipPackagePart ssPart = null;

            foreach (var part in Parts.Values)
            {
                if (part.ContentType != ContentTypes.contentTypeSharedString)
                {
                    part.WriteZip(os);
                }
                else
                {
                    ssPart = part;
                }
            }

            //Shared strings must be saved after all worksheets. The ss dictionary is populated when that workheets are saved (to get the best performance).
            if (ssPart != null)
            {
                ssPart.WriteZip(os);
            }
            os.Flush();

            os.Close();
            os.Dispose();

            //return ms;
        }
コード例 #2
0
ファイル: ZipPackage.cs プロジェクト: cosmos7603/ERP
        internal MemoryStream Save()
        {
            var             ms  = new MemoryStream();
            var             enc = Encoding.UTF8;
            ZipOutputStream os  = new ZipOutputStream(ms, true);

            os.CompressionLevel = (Ionic.Zlib.CompressionLevel)_compression;
            /**** ContentType****/
            var entry = os.PutNextEntry("[Content_Types].xml");

            byte[] b = enc.GetBytes(GetContentTypeXml());
            os.Write(b, 0, b.Length);
            /**** Top Rels ****/
            _rels.WriteZip(os, "_rels\\.rels");
            ZipPackagePart ssPart = null;

            foreach (var part in Parts.Values)
            {
                if (part.ContentType != ExcelPackage.contentTypeSharedString)
                {
                    part.WriteZip(os);
                }
                else
                {
                    ssPart = part;
                }
            }
            //Shared strings must be saved after all worksheets. The ss dictionary is populated when that workheets are saved (to get the best performance).
            if (ssPart != null)
            {
                ssPart.WriteZip(os);
            }
            os.Flush();
            os.Close();
            os.Dispose();
            return(ms);
        }