public Paras CreateCashFile([FromBody] Paras paras)
        {
            string webRootPath = _hostingEnvironment.WebRootPath;
            var    addrUrl     = webRootPath + $@"\temp\{paras.FileName}";

            if (System.IO.File.Exists(addrUrl))
            {
                System.IO.File.Delete(addrUrl);
            }
            string sqlstring = $"Select * from {paras.ViewName} where {paras.Where}";
            var    dataList  = _context.Set <CashBill>().FromSql(sqlstring).ToList();

            //创建Excel文件的对象
            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
            //添加一个sheet
            NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
            //获取list数据
            NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
            row1.CreateCell(0).SetCellValue("单号");
            row1.CreateCell(1).SetCellValue("状态");
            row1.CreateCell(2).SetCellValue("开票日期");
            row1.CreateCell(3).SetCellValue("购买性质");
            row1.CreateCell(4).SetCellValue("购买资质");

            row1.CreateCell(5).SetCellValue("客户属性");
            row1.CreateCell(6).SetCellValue("付款方式");
            row1.CreateCell(7).SetCellValue("保险公司");
            row1.CreateCell(8).SetCellValue("优惠金额");
            row1.CreateCell(9).SetCellValue("新车款金额");

            row1.CreateCell(10).SetCellValue("分期首付款金额");
            row1.CreateCell(11).SetCellValue("保险费金额");
            row1.CreateCell(12).SetCellValue("购置税金额");
            row1.CreateCell(13).SetCellValue("金融服务费金额");
            row1.CreateCell(14).SetCellValue("装饰费金额");

            row1.CreateCell(15).SetCellValue("交车综合服务费");
            row1.CreateCell(16).SetCellValue("安心服务费");
            row1.CreateCell(17).SetCellValue("贴心服务费");
            row1.CreateCell(18).SetCellValue("玻璃保障服务费");
            row1.CreateCell(19).SetCellValue("刷卡费金额");

            row1.CreateCell(20).SetCellValue("其他金额");
            row1.CreateCell(21).SetCellValue("应收金额总计");
            row1.CreateCell(22).SetCellValue("开票金额");
            row1.CreateCell(23).SetCellValue("已付订金");
            row1.CreateCell(24).SetCellValue("旧车置换金额");

            row1.CreateCell(25).SetCellValue("金融分期尾款金额");
            row1.CreateCell(26).SetCellValue("其他金额");
            row1.CreateCell(27).SetCellValue("实收金额总计");
            row1.CreateCell(28).SetCellValue("保险费");
            row1.CreateCell(29).SetCellValue("装修费");

            row1.CreateCell(30).SetCellValue("佣金");
            row1.CreateCell(31).SetCellValue("维修费");
            row1.CreateCell(32).SetCellValue("汽油费");
            row1.CreateCell(33).SetCellValue("其他");
            row1.CreateCell(34).SetCellValue("审核人");

            row1.CreateCell(35).SetCellValue("审核结果");
            row1.CreateCell(36).SetCellValue("审核意见");
            row1.CreateCell(37).SetCellValue("审核时间");
            row1.CreateCell(38).SetCellValue("备注");
            //将数据逐步写入sheet1各个行
            for (int i = 0; i < dataList.Count; i++)
            {
                NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);

                rowtemp.CreateCell(0).SetCellValue(dataList[i].OrderId);
                rowtemp.CreateCell(1).SetCellValue(dataList[i].Status);
                rowtemp.CreateCell(2).SetCellValue(dataList[i].InvoiceDate);
                rowtemp.CreateCell(3).SetCellValue(dataList[i].BuyType);
                rowtemp.CreateCell(4).SetCellValue(dataList[i].BuyLicense);

                rowtemp.CreateCell(5).SetCellValue(dataList[i].CustAttr);
                rowtemp.CreateCell(6).SetCellValue(dataList[i].PayType);
                rowtemp.CreateCell(7).SetCellValue(dataList[i].InsureCompany);
                rowtemp.CreateCell(8).SetCellValue(dataList[i].Discount);
                rowtemp.CreateCell(9).SetCellValue((double)dataList[i].NewCarFee);

                rowtemp.CreateCell(10).SetCellValue((double)dataList[i].FirstFee);
                rowtemp.CreateCell(11).SetCellValue((double)dataList[i].InsureFee);
                rowtemp.CreateCell(12).SetCellValue((double)dataList[i].BuyTaxFee);
                rowtemp.CreateCell(13).SetCellValue((double)dataList[i].FinanceSerFee);
                rowtemp.CreateCell(14).SetCellValue((double)dataList[i].DecorateFee);

                rowtemp.CreateCell(15).SetCellValue((double)dataList[i].TakeAllFee);
                rowtemp.CreateCell(16).SetCellValue((double)dataList[i].TakeCareFee);
                rowtemp.CreateCell(17).SetCellValue((double)dataList[i].IntimateFee);
                rowtemp.CreateCell(18).SetCellValue((double)dataList[i].GlassSerFee);
                rowtemp.CreateCell(19).SetCellValue((double)dataList[i].CardCashFee);

                rowtemp.CreateCell(20).SetCellValue((double)dataList[i].OtherFee);
                rowtemp.CreateCell(21).SetCellValue((double)dataList[i].ShouldAllFee);
                rowtemp.CreateCell(22).SetCellValue((double)dataList[i].InvoiceFee);
                rowtemp.CreateCell(23).SetCellValue((double)dataList[i].Deposit);
                rowtemp.CreateCell(24).SetCellValue((double)dataList[i].OldChangeFee);

                rowtemp.CreateCell(25).SetCellValue((double)dataList[i].LastFee);
                rowtemp.CreateCell(26).SetCellValue((double)dataList[i].OtherFee2);
                rowtemp.CreateCell(27).SetCellValue((double)dataList[i].RealAllFee);
                rowtemp.CreateCell(28).SetCellValue((double)dataList[i].BaoxianFee);
                rowtemp.CreateCell(29).SetCellValue((double)dataList[i].ZhuangxFee);

                rowtemp.CreateCell(30).SetCellValue((double)dataList[i].Commission);
                rowtemp.CreateCell(31).SetCellValue((double)dataList[i].MaintainFee);
                rowtemp.CreateCell(32).SetCellValue((double)dataList[i].GasFee);
                rowtemp.CreateCell(33).SetCellValue((double)dataList[i].OtherFee3);
                rowtemp.CreateCell(34).SetCellValue(dataList[i].Auditor);


                rowtemp.CreateCell(35).SetCellValue(dataList[i].AuditResult);
                rowtemp.CreateCell(36).SetCellValue(dataList[i].AuditSuggest);
                rowtemp.CreateCell(37).SetCellValue(dataList[i].AuditTime);
                rowtemp.CreateCell(38).SetCellValue(dataList[i].Remark);
            }
            // 写入到客户端
            using (FileStream fs = new FileStream(addrUrl, FileMode.Create))
            {
                book.Write(fs);
            }
            book = null;
            return(paras);
        }
Esempio n. 2
0
 public virtual IEnumerable <T> GetAll()
 {
     return(_context.Set <T>().AsEnumerable());
 }