public byte[] Export <TData, TColumn>(ExportDataHaveColumnModel <TData, TColumn> model)
            where TData : HavePropertyModel
            where TColumn : CustomizedColumnModel
        {
            IWorkbook workbook          = new XSSFWorkbook();
            ISheet    sheet             = workbook.CreateSheet(typeof(TData).Name);
            var       columns           = _exportColumnProvider.Provide <TData>();
            var       customizedColumns = model.Columns;
            //表头
            IRow rowHead     = sheet.CreateRow(0);
            int  columnIndex = 0;

            foreach (var column in columns)
            {
                ICell cell = rowHead.CreateCell(columnIndex);
                cell.SetCellValue(column.DisplayName);
                columnIndex++;
            }
            foreach (var column in customizedColumns)
            {
                ICell cell = rowHead.CreateCell(columnIndex);
                cell.SetCellValue(column.Name);
                columnIndex++;
            }

            var rowIndex = 1;

            foreach (var data in model.Datas)
            {
                IRow rowBody          = sheet.CreateRow(rowIndex);
                int  columnValueIndex = 0;
                foreach (var column in columns)
                {
                    ICell cell  = rowBody.CreateCell(columnValueIndex);
                    var   value = column.Property.GetValue(data);
                    cell.SetCellValue(value == null ? string.Empty : value.ToString());
                    columnValueIndex++;
                }
                foreach (var column in customizedColumns)
                {
                    ICell cell = rowBody.CreateCell(columnValueIndex);
                    cell.SetCellValue(data.GetPropertyValue(column.Id));
                    columnValueIndex++;
                }
                rowIndex++;
            }
            using (MemoryStream stream = new MemoryStream())
            {
                workbook.Write(stream);
                var buffer = stream.GetBuffer();
                stream.Close();
                return(buffer);
            }
        }
        public ActionResult Export(CustomerPageQueryModel query)
        {
            var customers  = _customerSearchService.GetCustomers(query);
            var properties = _customerPropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <CustomerModel, CustomerPropertyModel>
            {
                Datas   = customers,
                Columns = properties
            };
            var datas    = _dataExporter.Export <CustomerModel, CustomerPropertyModel>(model);
            var fileName = _dataExporter.CreateFileName("客户");

            return(File(datas, "application/ms-excel", fileName));
        }
Ejemplo n.º 3
0
        public ActionResult Export(EmployeePageQueryModel query)
        {
            var Employee   = _employeeSearchService.GetEmployee(query);
            var properties = _employeePropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <EmployeeModel, EmployeePropertyModel>
            {
                Datas   = Employee,
                Columns = properties
            };
            var fileName = _dataExporter.CreateFileName("员工记录");
            var datas    = _dataExporter.Export <EmployeeModel, EmployeePropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }
Ejemplo n.º 4
0
        public ActionResult Export(AttendancePageQueryModel query)
        {
            var Attendance = _attendanceSearchService.GetAttendance(query);
            var properties = _attendancePropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <AttendanceModel, AttendancePropertyModel>
            {
                Datas   = Attendance,
                Columns = properties
            };
            var fileName = _dataExporter.CreateFileName("员工记录");
            var datas    = _dataExporter.Export <AttendanceModel, AttendancePropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }
        public ActionResult Export(GoodsPageQueryModel query)
        {
            var goods      = _goodsSearchService.GetGoods(query);
            var properties = _goodsPropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <GoodsModel, GoodsPropertyModel>
            {
                Datas   = goods,
                Columns = properties
            };
            var fileName = _dataExporter.CreateFileName("商品");
            var datas    = _dataExporter.Export <GoodsModel, GoodsPropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }
Ejemplo n.º 6
0
        public ActionResult Export(StockPageQueryModel query)
        {
            var stock      = _stockSearchService.GetStock(query);
            var properties = _stockPropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <StockModel, StockPropertyModel>
            {
                Datas   = stock,
                Columns = properties
            };

            _stockWrappers.ToList().ForEach(wrapper =>
            {
                wrapper.Wrapper(stock);
            });
            var fileName = _dataExporter.CreateFileName("库存记录");
            var datas    = _dataExporter.Export <StockModel, StockPropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }
        public ActionResult Export(PurchasePageQueryModel query)
        {
            var purchase   = _purchaseSearchService.GetPurchase(query);
            var properties = _purchasePropertyService.SearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <PurchaseModel, PurchasePropertyModel>
            {
                Datas   = purchase,
                Columns = properties
            };

            _purchaseWrappers.ToList().ForEach(wrapper =>
            {
                wrapper.Wrapper(purchase);
            });
            var fileName = _dataExporter.CreateFileName("采购单");
            var datas    = _dataExporter.Export <PurchaseModel, PurchasePropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }
        public ActionResult Export(CustomerFinancePageQueryModel query)
        {
            var customerFinances = _financeSearchService.GetCustomerFinances(query);

            _financeWrappers.ToList().ForEach(wraper =>
            {
                wraper.Wrapper(customerFinances);
            });
            var properties = _propertySearchService.GetColumns();
            var model      = new ExportDataHaveColumnModel <CustomerFinanceModel, CustomerFinancePropertyModel>
            {
                Datas   = customerFinances,
                Columns = properties
            };
            var fileName = _dataExporter.CreateFileName("客户财务");
            var datas    = _dataExporter.Export <CustomerFinanceModel, CustomerFinancePropertyModel>(model);

            return(File(datas, "application/ms-excel", fileName));
        }