在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using OfficeOpenXml; private void TaskCalculatePBOCScore(byte[] buffer, string fileId) { using (var stream = new MemoryStream(buffer)) { using (var package = new ExcelPackage(stream)) { var sheet = package.Workbook.Worksheets.FirstOrDefault(); if (sheet != null) { sheet.Cells[1, 12].Value = "PA(Total_Fraud_Score)"; sheet.Cells[1, 13].Value = "PA(Fraud_Score_Grade)"; sheet.Cells[1, 14].Value = "PA(Blacklist_Type_Name)"; sheet.Cells[1, 15].Value = "PA(Blacklist_Type_Discription)"; var dimension = sheet.Dimension; var index = dimension.Start.Row + 1; var end = dimension.End.Row + 1; while (index < end) { sheet.Cells[index, 12].Value = "individualFraudScore.Total_Fraud_Score.ToString()"; sheet.Cells[index, 13].Value = "individualFraudScore.Fraud_Score_Grade.ToString()"; sheet.Cells[index, 14].Value = "individualFraudScore.Blacklist_Type_Name.ToString()"; sheet.Cells[index, 15].Value = "individualFraudScore.Blacklist_Type_Discription.ToString()"; index++; } buffer = package.GetAsByteArray(); var content = BitConverter.ToString(buffer); HttpRuntime.Cache[fileId] = content; } } } } private void DownloadFile(HttpRequest request, HttpResponse response) { response.Clear(); response.AddHeader("content-disposition", $"attachment; filename={DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx"); response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; var fileId = request["fileId"]; var content = HttpRuntime.Cache[fileId] as string; if (!string.IsNullOrEmpty(content)) { content = content.Replace("-", ""); var buffer = Enumerable.Range(0, content.Length) .Where(p => p % 2 == 0) .Select(p => Convert.ToByte(content.Substring(p, 2), 16)) .ToArray(); response.OutputStream.Write(buffer, 0, buffer.Length); } HttpRuntime.Cache.Remove(fileId); HttpRuntime.Cache.Remove(fileId + PROGRESS); }
|
请发表评论