日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ZipOutputStream 用法 小计

發布時間:2024/4/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZipOutputStream 用法 小计 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

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, 0, 0, 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就創建好了 0kbs.SetLevel(6); // 0 - store only to 9 - means best compressions.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, 0, 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 = "123";workbook = (HSSFWorkbook)WorkbookFactory.Create(file);//workbook.WriteProtectWorkbook("123456", "");//設置新密碼//NPOIHelper.ExcelPasswork(workbook, _ISysProjectService.GetProjectNameById(_userInfo.ProjectId)); workbook.WriteProtectWorkbook("", "");//設置密碼 }HSSFSheet sheet = (HSSFSheet)workbook.GetSheetAt(0);PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));int rowheight = 25;int colheight = 25 * 256;#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(0);//HSSFRow headerRow = (HSSFRow)workbook.GetSheetAt(0);headerRow.HeightInPoints = rowheight;//行高 if (strHeaderText.Contains("ATM Combination Code")){headerRow.CreateCell(0).SetCellValue("Export Date:" + DateTime.Today.Date.ToString("MM/dd/yyyy") + " " + strHeaderText);}else{headerRow.CreateCell(0).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 = 20;fonth.Boldweight = 700;hvstyleh.SetFont(fonth);CellRangeAddress m_region = new CellRangeAddress(0, 1, 0, titles.Count() - 1); //合并0列的n--n+2行 sheet.AddMergedRegion(m_region);setcelltag(m_region, hvstyleh, sheet);headerRow.GetCell(0).CellStyle = hvstyleh;var day = DateTime.Now;int rowIndex = 2;#endregion#region sheet頁的表頭定義if (ptlist != null){if (ptlist.Count > 0){rowIndex = 3;HSSFRow ttdataRow = (HSSFRow)sheet.CreateRow(rowIndex - 1);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 = new CellRangeAddress(2, 2, 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 定義表頭int cellcnt = 0;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 = 0;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#endregionSystem.IO.MemoryStream ms = new System.IO.MemoryStream();workbook.Write(ms);return ms;}

?

總結

以上是生活随笔為你收集整理的ZipOutputStream 用法 小计的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。