Пример #1
0
        public JsonResult Export()
        {
            try
            {
                string webRootPath = HostingEnvironment.WebRootPath;
                string basePath    = webRootPath + "/excelTemp/";

                if (!Directory.Exists(basePath))
                {
                    Directory.CreateDirectory(basePath);
                }

                string fileName = Guid.NewGuid().ToString() + ".xlsx";
                var    filePath = basePath + fileName;

                List <UserDTO>          resultRows = UsersRepository.GetListByName("admin");
                GenerateSheet <UserDTO> sheet      = new GenerateSheet <UserDTO>(resultRows, "sheet1");
                GenerateExcel           excel      = new GenerateExcel(filePath); //目录
                excel.AddSheet(sheet);
                excel.ExportExcel();

                return(new JsonResult(new { isok = true, data = "导出成功", msg = "成功" }));
            }
            catch (Exception exp)
            {
                logger.Info("上传文件错误:" + exp.Message);
                return(new JsonResult(new { isok = false, data = exp.Message, msg = "失败" }));
            }
        }
Пример #2
0
        public static void ExportExcel(string excelPath, MonthPayOffExportFilter filter)
        {
            var dataSource = Core.Receivable.MonthPayOff.GetById(filter);
            List <MonthPayOff> queryData = dataSource.ToList();

            var loadBillData = LoadBillReconciliation.GetByMonthPayOffExportFilter(new LBRForMonthPayOffExportFilter()
            {
                MonthPayOffIDList = filter.ListID
            });
            List <LoadBillReconciliation> loadBillList = loadBillData.ToList();

            GenerateExcel genExcel = new GenerateExcel();

            genExcel.SheetList.Add(new MonthPayOffSheet(queryData, "总表"));
            genExcel.SheetList.Add(new LoadBillSheet(loadBillList, "提单汇总"));
            genExcel.SheetList.Add(new WayBillSummarySheet(new List <WayBillReconciliation>(), "运单汇总"));
            genExcel.ExportExcel(excelPath);
        }