コード例 #1
0
ファイル: HomeController.cs プロジェクト: bonyRocker/CCM
        public ActionResult DownloadFile(IEnumerable<long> idList)
        {
            try
            {
                wb = new XSSFWorkbook();
                sh = (XSSFSheet)wb.CreateSheet("Sheet1");
                List<CARDCHEREUISITION> list = new List<CARDCHEREUISITION>();
                var row = sh.CreateRow(0);

                row.CreateCell(0).SetCellValue("Bank");

                row.CreateCell(1).SetCellValue("Card No");

                row.CreateCell(2).SetCellValue("No of Books/Leaves");

                row.CreateCell(3).SetCellValue("Delivery Brn/Channel");

                row.CreateCell(4).SetCellValue("RoutingNo?");

                row.CreateCell(5).SetCellValue("Transaction Code");
                foreach (var id in idList)
                {
                    var aItem = db.CARDCHEREUISITION.FirstOrDefault(x => x.ID==id);
                    list.Add(aItem);
                }
               // var list = db.CARDCHEREUISITION.Where(x => x.STATUS == 7).ToList();

                foreach (var card in list.Select((value, index) => new { value, index }))
                {
                    row = sh.CreateRow(card.index +1);

                    row.CreateCell(0).SetCellValue("OBL");
                    row.CreateCell(1).SetCellValue(card.value.CARDNO);
                    row.CreateCell(2).SetCellValue(card.value.LEAFNO);
                    row.CreateCell(3).SetCellValue(card.value.BRANCHINFO.BRANCHNAME);
                    row.CreateCell(4).SetCellValue("Test Routing");
                    row.CreateCell(5).SetCellValue("Test Transaction");
                }
                //using (var fs = new FileStream(@"~/test.xls", FileMode.Create, FileAccess.Write))
                //{
                //    wb.Write(fs);
                //}
                using (var exportData = new MemoryStream())
                {

                    wb.Write(exportData);
                    exportData.Close();

                    var buffer = exportData.GetBuffer();
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.BinaryWrite(buffer);

                    Response.End();

                    //string saveAsFileName = string.Format("Cheque_Requisition{0:d}.xls", DateTime.Now).Replace("/", "-");
                    //Response.Clear();
                    ////Response.ContentType = "application/octet-stream";
                    //Response.ContentType = "application/vnd.ms-excel";
                    //Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    //Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
                    //Response.BinaryWrite(exportData.GetBuffer());
                    //Response.End();

                }

                return RedirectToAction("Index");

            }
            catch (Exception exception)
            {

                return RedirectToAction("Error", "Home", new { Area = "" });
            }
        }
コード例 #2
0
        private XSSFDataValidation CreateValidation(XSSFSheet sheet)
        {
            //create the cell that will have the validation applied
            IRow row = sheet.CreateRow(0);
            row.CreateCell(0);

            IDataValidationHelper dataValidationHelper = sheet.GetDataValidationHelper();

            IDataValidationConstraint constraint = dataValidationHelper.CreateCustomConstraint("true");
            XSSFDataValidation validation = (XSSFDataValidation)dataValidationHelper.CreateValidation(constraint, new CellRangeAddressList(0, 0, 0, 0));
            return validation;
        }