ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile));

构造函数之后

文件就已经创建出来了 只是 0kb

s.Write(buffer, 0, buffer.Length);    内容写进去了  写到服务器里面了  还设置了密码

最后 return 出来

服务器上还是有

public FileResult ExcelPrint(string bgrq, string endrq, string jijubianhao, string customerName, string status, string numMin, string numMax)
        {
            var user = _isysUserService.GetById(_userInfo.UserId);
            int? _numMin = string.IsNullOrEmpty(numMin) ? null : (int?)int.Parse(numMin);
            int? _numMax = string.IsNullOrEmpty(numMax) ? null : (int?)int.Parse(numMax);
            DateTime? _BgRq = string.IsNullOrEmpty(bgrq) ? null : (DateTime?)Convert.ToDateTime(bgrq);
            DateTime? _EndRq = string.IsNullOrEmpty(endrq) ? null : (DateTime?)Convert.ToDateTime(endrq);
            int pagecnt, thresholdCount;
            List<VMSelectItem> list = _IAtmAtmService.GetDataList(_BgRq, _EndRq, jijubianhao, customerName, status, , , out pagecnt, "", "", out thresholdCount, _numMin, _numMax, "export");

            string[] titles = { "Atm ID", "Location Name", "Customer", "Old Password", "Current Password", "Change By", "Change Time" };
            string[] props = { "One", "BeiZhu", "Remark", "Three", "Two", "UserName", "banci" };
            List<PorpTitle> ptlist = new List<PorpTitle>();

            string _BranchCode = _ISysProjectService.GetProjectNameById(_userInfo.ProjectId);
            string title = "ATM Combination Code-" + _BranchCode + "           Export by: " + user.UserName;
            DateTime dt = DateTime.Now;
            string dateTime = dt.ToString("yyMMdd");//yyMMddHHmmssfff
            string dateTimess = dt.ToString("yyMMddHHmmssfff");//yyMMddHHmmssfff      

            //MemoryStream ms = NpoiToExcel.ListToExcel(list, title, titles, props, ptlist);
            //ms.Seek(0, SeekOrigin.Begin);
            //string fileName = "ATM Combination Code_" + _BranchCode + dateTime + ".xls";
            //return File(ms, "application/vnd.ms-excel", fileName);

            string pass = "COMBI00";
            var syspro = _ISysProjectService.GetById(_userInfo.ProjectId);
            pass = syspro == null ? pass : "COMBI" + syspro.Code;
            string outfileName = "ATM Combination Code_" + _BranchCode + dateTime + ".xls";
            string fileName = "ATM Combination Code_" + _BranchCode + dateTimess + ".zip";
            string fileNameout = "ATM Combination Code_" + _BranchCode + dateTime + ".zip";
            MemoryStream ms = this.ListToExcel2("CC.xls", list, title, titles, props, ptlist);    // ms 是流内容   内存的流 已写入过内容
            string strpath = Server.MapPath("/Upload/Combination/" + fileName);  // 保存路径
            Common.ZipUtil.ZipFileMain(ms.ToArray(), strpath, pass, outfileName);  // 保存位置名字(zip)   密码   zip中内容文件名称
            return File(strpath, "application/octet-stream", fileNameout);   // 返回
        }
public static void ZipFileMain(byte[] buffer, string ZipedFile, string password,string outname)
        {
            ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile));  // 构造出来 zip就创建好了 0kb
            s.SetLevel(); // 0 - store only to 9 - means best compression
            s.Password = password;  // 密码
            //打开压缩文件
            //FileStream fs = File.OpenRead(FileToZip);
            //byte[] buffer = new byte[fs.Length];
            //fs.Read(buffer, 0, buffer.Length);

            //Array arr = FileToZip.Split('\\');
            //string le = arr.GetValue(arr.Length - 1).ToString();
            ZipEntry entry = new ZipEntry(outname);   // outname 内容名称
            entry.DateTime = DateTime.Now;
            entry.Size = buffer.Length;  // 内容大小
            s.PutNextEntry(entry);//编写新的ZIP文件条目
            s.Write(buffer, , buffer.Length); //写出 这句就写出来了
            s.Finish();
            s.Close();
            //Stream output = (Stream)s;
            //return output;
        }
public MemoryStream ListToExcel2<T>(string tmpnm, List<T> data, string strHeaderText, string[] titles, string[] props = null, List<PorpTitle> ptlist = null)
        {
            ////
            string configurl = System.Configuration.ConfigurationSettings.AppSettings["TempletsPath"].ToString();
            string FileFullPath = Server.MapPath(configurl) + tmpnm;

            if (!System.IO.File.Exists(FileFullPath))
            {
                return null;
            }

            HSSFWorkbook workbook = new HSSFWorkbook();
            string pass = "COMBI00";
            var syspro = _ISysProjectService.GetById(_userInfo.ProjectId);
            pass = syspro == null ? pass : "COMBI" + syspro.Code;

            using (FileStream file = new FileStream(FileFullPath, FileMode.Open, FileAccess.Read))
            {
                //NPOIHelper.ExcelPasswork(workbook, _ISysProjectService.GetProjectNameById(_userInfo.ProjectId));
                NPOI.HSSF.Record.Crypto.Biff8EncryptionKey.CurrentUserPassword = ";
                workbook = (HSSFWorkbook)WorkbookFactory.Create(file);
                //workbook.WriteProtectWorkbook("123456", "");//设置新密码
                //NPOIHelper.ExcelPasswork(workbook, _ISysProjectService.GetProjectNameById(_userInfo.ProjectId));
                workbook.WriteProtectWorkbook("", "");//设置密码
            }

            HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt();
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));

            ;
             * ;
            #region 基础数据定义
            HSSFCellStyle cellstyle = (HSSFCellStyle)workbook.CreateCellStyle();
            cellstyle.BorderBottom = (BorderStyle)CellBorderType.THIN;
            cellstyle.BorderLeft = (BorderStyle)CellBorderType.THIN;
            cellstyle.BorderRight = (BorderStyle)CellBorderType.THIN;
            cellstyle.BorderTop = (BorderStyle)CellBorderType.THIN;
            cellstyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER; // 居中
            cellstyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
            #endregion

            #region 首行首列定义
            HSSFRow headerRow = (HSSFRow)sheet.CreateRow();
            //HSSFRow headerRow = (HSSFRow)workbook.GetSheetAt(0);
            headerRow.HeightInPoints = rowheight;//行高
            if (strHeaderText.Contains("ATM Combination Code"))
            {
                headerRow.CreateCell().SetCellValue("Export Date:" + DateTime.Today.Date.ToString("MM/dd/yyyy") + "     " + strHeaderText);
            }
            else
            {
                headerRow.CreateCell().SetCellValue(strHeaderText);
            }

            HSSFCellStyle hvstyleh = (HSSFCellStyle)workbook.CreateCellStyle();
            hvstyleh.BorderBottom = (BorderStyle)CellBorderType.THIN;
            hvstyleh.BorderLeft = (BorderStyle)CellBorderType.THIN;
            hvstyleh.BorderRight = (BorderStyle)CellBorderType.THIN;
            hvstyleh.BorderTop = (BorderStyle)CellBorderType.THIN;
            hvstyleh.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER; // 居中
            hvstyleh.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER; // 居中
            hvstyleh.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
            HSSFFont fonth = (HSSFFont)workbook.CreateFont();
            fonth.FontHeightInPoints = ;
            fonth.Boldweight = ;
            hvstyleh.SetFont(fonth);
            CellRangeAddress m_region = , , , titles.Count() - );  //合并0列的n--n+2行
            sheet.AddMergedRegion(m_region);
            setcelltag(m_region, hvstyleh, sheet);
            headerRow.GetCell().CellStyle = hvstyleh;
            var day = DateTime.Now;
            ;
            #endregion

            #region sheet页的表头定义
            if (ptlist != null)
            {
                )
                {
                    rowIndex = ;
                    HSSFRow ttdataRow = (HSSFRow)sheet.CreateRow(rowIndex - );
                    ttdataRow.HeightInPoints = rowheight;//行高
                    foreach (PorpTitle title in ptlist)
                    {
                        HSSFCell ttCell = (HSSFCell)ttdataRow.CreateCell(title.Poss);
                        ttCell.SetCellValue(title.TitleNM);
                        if (title.Poss != title.Pose)
                        {
                            CellRangeAddress m_region1 = , , title.Poss, title.Pose);  //合并0列的n--n+2行
                            sheet.AddMergedRegion(m_region1);
                            setcelltag(m_region1, cellstyle, sheet);
                            ttCell.CellStyle = cellstyle;
                        }
                        else
                        {
                            ttCell.CellStyle = cellstyle;
                        }
                    }
                }
            }

            #endregion

            #region 表记录记录
            var jyzindex = rowIndex;

            #region 定义表头
            ;
            HSSFRow dataRow = (HSSFRow)sheet.CreateRow(jyzindex);
            dataRow.HeightInPoints = rowheight;//行高
            HSSFCell newCell;
            foreach (string prop in titles)
            {
                newCell = (HSSFCell)dataRow.CreateCell(cellcnt);
                newCell.SetCellValue(prop);
                newCell.CellStyle = cellstyle;
                sheet.SetColumnWidth(cellcnt, colheight);
                cellcnt++;
            }
            #endregion

            #region 定义表内容
            jyzindex++;
            foreach (T item in data)
            {
                dataRow = (HSSFRow)sheet.CreateRow(jyzindex);
                dataRow.HeightInPoints = rowheight;//行高
                cellcnt = ;

                if (props != null)
                {
                    foreach (string prop in props)
                    {
                        PropertyDescriptor prop1 = properties[prop];
                        var val = "";
                        try { val = ConvertHelper.ToStr(prop1.GetValue(item) ?? DBNull.Value); }
                        catch { }
                        newCell = (HSSFCell)dataRow.CreateCell(cellcnt);
                        newCell.SetCellValue(val);
                        newCell.CellStyle = cellstyle;
                        sheet.SetColumnWidth(cellcnt, colheight);
                        cellcnt++;
                    }
                }
                else
                {
                    foreach (PropertyDescriptor prop in properties)
                    {
                        var val = "";
                        try { val = ConvertHelper.ToStr(prop.GetValue(item) ?? DBNull.Value); }
                        catch { }
                        newCell = (HSSFCell)dataRow.CreateCell(cellcnt);
                        newCell.SetCellValue(val);
                        newCell.CellStyle = cellstyle;
                        sheet.SetColumnWidth(cellcnt, colheight);
                        cellcnt++;
                    }
                }
                jyzindex++;
            }
            //sheet.ProtectSheet("password");
            #endregion

            #endregion

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            workbook.Write(ms);
            return ms;
        }

ZipOutputStream 用法 小计的更多相关文章

  1. git常用命令及用法小计

    git init 初始化一个本地git仓库repository git status 查看状态 git add <file> 将工作区修改加到暂存区(stage) git commit - ...

  2. pmap用法小计

    By francis_hao    Aug 4,2017   pmap-报告进程的内存映射.   概要 pmap [options] pid [...]   描述 pmap命令用来报告一个或多个进程的 ...

  3. sql小计汇总 rollup用法实例分析

    这里介绍sql server2005里面的一个使用实例: ),city ),score int) GO 1. 只有一个汇总 select province as 省,sum(score) as 分数 ...

  4. SQLSERVER 使用 ROLLUP 汇总数据,实现分组统计,合计,小计

    表结构: CREATE TABLE [dbo].[Students]( ,) NOT NULL, ) NULL, [Sex] [int] NOT NULL, ) NULL, ) NULL, , ) N ...

  5. PB gird类型数据窗口 设置分组、分组小计、合计

    今天遇到一个需求,gird表格数据如下:  部门  类型 数据   A  类型1  1  A  类型2  2  B  类型1  3  B  类型2  4   合计 10 实际需要显示的结果为:  部门 ...

  6. 简单的angular购物车商品小计

    <!DOCTYPE html> <html lang="en" ng-app="shopApp"> <head> <m ...

  7. C#给DataTable添加序号、C#给DataTable添加合计、小计

    /// <summary>        /// 给DataTable添加序号        /// </summary>        /// <param name= ...

  8. SAP ALV中同一列的不同行显示不同的小数位,并能够总计,小计

    物料数量字段,根据物料类型的不同,来显示不同的小数位:要求有点苛刻: 首先,要能够总计和小计的话,这一列的字段类型必须是数值类型. 这样的话,就不能通过截取的方式改变不同行的小数位. 以下是两种思路: ...

  9. 每日学习心得:SQL查询表的行列转换/小计/统计(with rollup,with cube,pivot解析)

    2013-8-20 1.    SQL查询表的行列转换/小计/统计(with  rollup,with cube,pivot解析) 在实际的项目开发中有很多项目都会有报表模块,今天就通过一个小的SQL ...

随机推荐

  1. js只能输入汉字

    var reg = new RegExp("[\\u4E00-\\u9FFF]+","g"); if(reg.test(val)){            al ...

  2. 刷题总结——解方程(NOIP2014)

    题目: 题目描述 已知多项式方程: a0+a1x+a2x2+…+anxn=0 求这个方程在[1,m]内的整数解(n 和 m 均为正整数). 输入格式 输入共 n+2 行. 第一行包含 2 个整数 n. ...

  3. 337. House Robber III(包含I和II)

    198. House Robber You are a professional robber planning to rob houses along a street. Each house ha ...

  4. Java如何获取ISO 8601时间

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); df.setTimeZone(TimeZ ...

  5. 从实际案例聊聊Java应用的GC优化

    转自美团点评技术博客:https://tech.meituan.com/jvm_optimize.html 当Java程序性能达不到既定目标,且其他优化手段都已经穷尽时,通常需要调整垃圾回收器来进一步 ...

  6. bzoj 4009 接水果 整体二分

    Description 先给出一些盘子, 用路径x-y表示, 有权值 再有Q个询问, 表示水果, 用路径x-y表示 如果盘子是水果的子路径, 可以接住 对于每个水果, 输出可以接住它的盘子的第k小权 ...

  7. 【CF1020A】New Building for SIS(签到)

    题意: 有n栋楼,从一栋楼某个地方,到大另一栋楼的某个地方,每栋楼给了连接楼的天桥,每走一层或者穿个一栋楼花费一分钟,求出起点到大目的点最少花费的时间 n,h<=1e8,q<=1e4 思路 ...

  8. js 函数arguments一种用法

    无意改同事的代码发现的 function toggle(){ var _arguments=arguments; var count=0; $("#more").click(fun ...

  9. 串口VMIN VTIME 详解

    原文地址: 以前跟着做过VxWorks的开发,主要通信方式是串口,因为底层BSP包已经做好了,串口通信非常简单.后来接触Linux,在一块OK6410上跑Linux串口通信,才发现原来天真的以为甚是简 ...

  10. 板子-GOD BLESS ALL OF YOU

    字符串: KMP #include<cstdio> #include<cstring> ; ]; ]; int l1,l2; void get_next() { next[]= ...