示例#1
0
        public async Task <ActionResult> DownloadExcelReport(eService _Query)
        {
            string Extension = ".xlsx";
            var    dt        = DateTime.ParseExact(_Query.SelectedTxnDateRange, "yyyyMM", CultureInfo.InvariantCulture);

            _Query.Month = Convert.ToInt16(dt.ToString("MM"));
            _Query.Year  = Convert.ToInt16(dt.ToString("yyyy"));
            int colIndex = 1, rowIndex = 4;
            var list       = (await MechSignUpService.GetIFrameMerchGeneralInfoes(_Query.BusnLocation, Convert.ToInt32(_Query.SelectedTxnType), _Query.Month, _Query.Year)).eServices;
            var headerName = string.Format("{0}_{1}", _Query.SelectedTxnType, _Query.SelectedTxnDateRange);

            headerName = headerName.Trim();
            var pkg  = CommonHelpers.PrepareExcelHeader(headerName, new string[] { "Posting Date", "Txn Date", "Card No", "RRN", "Quantity", "Amount", "MDR", "VAT Amount", "Net Amount" });
            var ws   = pkg.Workbook.Worksheets[1];
            var cell = ws.Cells[rowIndex, colIndex];

            foreach (var x in list)
            {
                colIndex   = 1;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.PostingDate;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.TxnDate;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.CardNo;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.RRN;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.Quantity;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.Amount;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.MDR;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.VatAmount;
                colIndex++;
                cell       = ws.Cells[rowIndex, colIndex];
                cell.Value = x.NetAmount;
                rowIndex++;
            }
            string contentType = CommonHelpers.ContentType(Extension);

            Byte[] bin = pkg.GetAsByteArray();
            return(File(bin, contentType, headerName + Extension));
        }