public byte[] GetZip()
        {
            if (!GetXaml())
                return null;

            MemoryStream ms = new MemoryStream();
            _ZipStream = null;

            ZipEntry ze;
            try
            {
                ZipWrap.Init();             // initialize the zipping utility (if needed)
                _ZipImages = new Dictionary<string, string>(); 

                _ZipStream = new ZipOutputStream(ms);

                // Need to build the Xaml
                int pageno = 1;
                foreach (fyiReporting.RDL.Page page in _Pages)
                {
                    string xaml = GenerateXaml(page);
                    string zp = string.Format("pg_{0}.xaml", pageno++);
                    ze = new ZipEntry(zp);
                    _ZipStream.PutNextEntry(ze);
                    _ZipStream.Write(xaml);
                }
                // output some meta data
                ze = new ZipEntry("meta.txt");
                _ZipStream.PutNextEntry(ze);
                _ZipStream.Write(string.Format("pagecount={0}&pagewidth={1}&pageheight={2}", 
                    _Pages.Count, PixelsX(_Pages.PageWidth), PixelsY(_Pages.PageHeight))); // to do more than one use & e.g. pagecount=1&pagewidth=121
                
                // all done
                _ZipStream.Finish();
                _ZipStream = null;
                return ms.ToArray();
            }
            finally
            {
                if (_ZipStream != null)
                {
                    _ZipStream.Finish();
                    _ZipStream = null;
                }
                ms.Close();
                _ZipImages = null;              // no longer need zipimage cache
            }
        }
        /// <summary>
        /// SaveZipImage saves the bytes to a zip entry and returns the name.  The passed cache is used
        /// to remember file names so that the same image isn't repeatedly saved.
        /// </summary>
        /// <param name="zipCache"></param>
        /// <param name="_ZipStream"></param>
        /// <param name="pi"></param>
        /// <returns></returns>
        internal static string SaveZipImage(Dictionary<string, string> zipCache, ZipOutputStream _ZipStream, PageImage pi)
        { 
            string imgname;
            imgname = (pi.Name != null)?
                string.Format("{0}.{1}", pi.Name, GetExtension(pi.ImgFormat)): 
                string.Format("i_{0}.{1}", zipCache.Count + 1, GetExtension(pi.ImgFormat));

            if (zipCache.ContainsKey(imgname))
                return imgname;

            zipCache.Add(imgname, imgname);

            ZipEntry ze = new ZipEntry(imgname);
            _ZipStream.PutNextEntry(ze);
            _ZipStream.Write(pi.ImageData, 0, pi.ImageData.Length);

            return imgname; 
        }
示例#3
0
        internal void WriteExcel(Stream str)
        {
            ZipOutputStream zip = null;

            try
            {
                zip = new ZipOutputStream(str);
                ZipEntry ze = new ZipEntry("[Content_Types].xml");
                zip.PutNextEntry(ze);
                zip.Write(CONTENT_TYPES);
                // docProps directory
                ze = new ZipEntry("docProps/");
                zip.PutNextEntry(ze);
                ze = new ZipEntry("docProps/app.xml");
                zip.PutNextEntry(ze);
                zip.Write(APPXML);
                ze = new ZipEntry("docProps/core.xml");
                zip.PutNextEntry(ze);
                zip.Write(COREXML);

                // xl directory
                ze = new ZipEntry("xl/");
                zip.PutNextEntry(ze);
                ze = new ZipEntry("xl/sharedStrings.xml");
                zip.PutNextEntry(ze);
                WriteStringCache(zip);
                ze = new ZipEntry("xl/styles.xml");
                zip.PutNextEntry(ze);
                WriteStyles(zip);
                ze = new ZipEntry("xl/workbook.xml");
                zip.PutNextEntry(ze);
                WriteWorkbook(zip);

                // xl/theme
                ze = new ZipEntry("xl/theme/");
                zip.PutNextEntry(ze);
                ze = new ZipEntry("xl/theme/theme1.xml");
                zip.PutNextEntry(ze);
                WriteTheme(zip);

                // xl/worksheets
                ze = new ZipEntry("xl/worksheets/");
                zip.PutNextEntry(ze);

                if (_Sheets.Count == 0)
                {   // output an empty work sheet
                    ze = new ZipEntry("xl/worksheets/sheet1.xml");
                    zip.PutNextEntry(ze);
                    WriteEmptyWorksheet(zip);
                }
                else
                {
                    // output the spreadsheets
                    foreach (SheetInfo sinfo in _Sheets)
                    {
                        string sname = string.Format("xl/worksheets/{0}.xml", sinfo.Name);
                        ze = new ZipEntry(sname);
                        zip.PutNextEntry(ze);
                        WriteData(zip, sinfo.Grid);                     // here's where the meat of the data goes
                    }
                }
                // xl/_rels
                ze = new ZipEntry("xl/_rels/");
                zip.PutNextEntry(ze);
                ze = new ZipEntry("xl/_rels/workbook.xml.rels");
                zip.PutNextEntry(ze);
                WriteWorkbookRels(zip);

                // _rels directory
                ze = new ZipEntry("_rels/");
                zip.PutNextEntry(ze);
                ze = new ZipEntry("_rels/.rels");
                zip.PutNextEntry(ze);
                zip.Write(RELS_RELS);
            }
            finally
            {
                if (zip != null)
                {
                    zip.Finish();
                }
            }
        }
示例#4
0
 public void PutNextEntry(ZipEntry ze)
 {
     object[] args = new object[] { ze.Value };
     _PutNextEntry.Invoke(_ZipOutputStream, args);
 }
示例#5
0
 public void PutNextEntry(ZipEntry ze)
 {
     object[] args = new object[] { ze.Value };
     _PutNextEntry.Invoke(_ZipOutputStream, args);
 }