Пример #1
0
        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="excelId"></param>
        /// <param name="accountItemIds"></param>
        /// <param name="financialDataItemIds"></param>
        /// <param name="qiJianTypeId"></param>
        /// <returns></returns>
        public Stream Process(int excelId, string accountItemIds, string financialDataItemIds, int qiJianTypeId, int onlyStatisticChildren, int xiangMuTreeTypeId, int statisticAccountChildren)
        {
            var result     = new List <List <string> >();
            var columnData = _financialDataExtendBLL.GetGridColumns(excelId, financialDataItemIds, onlyStatisticChildren, xiangMuTreeTypeId);
            var gridData   = _financialDataExtendBLL.GetGridData(excelId, accountItemIds, financialDataItemIds, qiJianTypeId, onlyStatisticChildren, xiangMuTreeTypeId, statisticAccountChildren);
            var columnList = new List <string>();

            foreach (var gridColumn in columnData.GridColumns)
            {
                columnList.Add(gridColumn.text);
            }
            result.Add(columnList);
            foreach (var dataDic in gridData.rows)
            {
                var dataList = new List <string>();
                foreach (var gridColumn in columnData.GridColumns)
                {
                    dataList.Add(dataDic[gridColumn.dataIndex]);
                }
                result.Add(dataList);
            }
            var excelBuilder = ExcelFactory.CreateBuilder();
            var sheet        = excelBuilder.InsertSheet("统计数据");

            sheet.InsertSheetContent(ExcelExportRequest.GetInstance(result));
            var stream = new MemoryStream();

            excelBuilder.Save(stream, SaveFormat.Xlsx);
            stream.Position = 0;
            return(stream);
        }
        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="excelId"></param>
        /// <returns></returns>
        public Stream Process(string ids)
        {
            var excelDatas = new List <List <string> >();

            excelDatas.Add(GetExcelTitel());
            var idsArr      = ids.Split(',');
            var companyList = new List <Company>();
            var areas       = _companyBll.GetAllArea();

            foreach (var id in idsArr)
            {
                if (string.IsNullOrEmpty(id))
                {
                    continue;
                }
                var idArr  = id.Split('_');
                var findId = Convert.ToInt32(idArr[1]);
                if (idArr[0] == "1")
                {
                    var companys = _companyBll.GetCompanyByAreaId(findId);
                    if (companys != null)
                    {
                        companyList.AddRange(companys);
                    }
                }
                else
                {
                    var company = _companyBll.GetCompanyByKey(findId);
                    if (company != null)
                    {
                        companyList.Add(company);
                    }
                }
            }
            foreach (var company in companyList)
            {
                var area           = areas.FirstOrDefault(x => x.AreaId == company.AreaId);
                var companyRecords = _companyBll.GetCompanyconnectrecordByCompanyId(company.CompanyId);
                if (companyRecords != null && companyRecords.Count > 0)
                {
                    foreach (var record in companyRecords)
                    {
                        excelDatas.Add(GetOneCellData(area, company, record));
                    }
                }
                else
                {
                    excelDatas.Add(GetOneCellData(area, company, new CompanyConnectRecord()));
                }
            }
            var excelBuilder = ExcelFactory.CreateBuilder();
            var sheet        = excelBuilder.InsertSheet("sheet1");

            sheet.InsertSheetContent(ExcelExportRequest.GetInstance(excelDatas));
            var stream = new MemoryStream();

            excelBuilder.Save(stream, SaveFormat.Xlsx);
            stream.Position = 0;
            return(stream);
        }