以Zip格式导出 [英] Export in Zip format

查看:151
本文介绍了以Zip格式导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有Gridview.我需要将数据导出到excel并将其压缩.

我曾经使用过dot net zip free dll.压缩文件没有excel.
需要帮助如何将excel文件包含在zip中吗?

以下代码创建了zip文件

Hi,
I have Gridview. I need to export the data to excel and zip it.

I had used dot net zip free dll. The zip file is not having the excel.
Need help how to include the excel file in zip?

The below code creates zip file

using Ionic.Zip;
using System.Text;
using System.IO;
using Ionic.Zlib;
protected void btn_Export_Click(object sender, EventArgs e)
    {
HtmlForm form = new HtmlForm();
        string attachment = "attachment; filename=Employee.xls";
        Response.ClearContent();
        Response.ContentType = "application/ms-excel";
        System.IO.StringWriter stw = new System.IO.StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        form.Controls.Add(grd);
        this.Controls.Add(form);
        form.RenderControl(htextw);

        var filesToInclude = new System.Collections.Generic.List<String>();
        if (filesToInclude.Count == 0)
        {
            Response.Clear();
            Response.BufferOutput = false;
            System.Web.HttpContext c = System.Web.HttpContext.Current;
            //string archiveName = String.Format("Employee.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
           string archiveName = String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "filename=" + archiveName);
           // ZipFile zip = new ZipFile();
            using (ZipFile zip = new ZipFile())
            {
                //zip.AddFile("export.xls", "content");
                        zip.Encryption = EncryptionAlgorithm.WinZipAes256;
                // filesToInclude is a string[] or List<String>
                zip.AddFiles(filesToInclude, "files");
                zip.Save(Response.OutputStream);
               // zip.Save(archiveName);
            }
            Response.Close();
        }

      }


谢谢
S.Guhananth


Thanks
S.Guhananth

推荐答案

可能会帮助您...
引用此链接...
http://viralsarvaiya.wordpress.com/2009/07/11/create -zip-file-using-dotnet/
may be this will helps u...
refere this link...
http://viralsarvaiya.wordpress.com/2009/07/11/create-zip-file-using-dotnet/


这篇关于以Zip格式导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆