Ejemplo n.º 1
0
        public ActionResult ExportByOrganization()
        {
            ExportByOrganizationArgs exportByOrganizationArgs = base.RequestArgs <ExportByOrganizationArgs>();

            exportByOrganizationArgs.Domain = base.UserContext.Domain.Id;
            FileInfo fileInfo = new FileInfo(ExcelHelper.ExportOrganization(_environment.ContentRootPath, exportByOrganizationArgs));

            return(this.RespondDataResult(fileInfo.Name));
        }
        public ActionResult ExportByOrganization()
        {
            ExportByOrganizationArgs exportByOrganizationArgs = base.RequestArgs <ExportByOrganizationArgs>();

            exportByOrganizationArgs.Domain = base.UserContext.Domain.Id;
            FileInfo fileInfo = new FileInfo(ExcelHelper.ExportOrganization(base.Server.MapPath("/"), exportByOrganizationArgs));

            return(this.RespondDataResult(fileInfo.Name));
        }
Ejemplo n.º 3
0
        public static string ExportOrganization(string rootPath, ExportByOrganizationArgs args)
        {
            List <WeeklyReport> arg_28_0 = ExcelHelper._weeklyReportManager.GetWeeklyReportListByOrganization(args.Domain, args.Organization, args.Year, args.WeekOfYear);
            List <WeeklyReport> list     = new List <WeeklyReport>();

            foreach (WeeklyReport current in arg_28_0)
            {
                if (args.UserList.Contains(current.User))
                {
                    list.Add(current);
                }
            }
            if (list.Count == 0)
            {
                return(null);
            }
            IWorkbook  workbook    = null;
            FileStream fileStream  = null;
            string     text        = Path.Combine(rootPath, ExcelHelper._templateFile);
            FileStream fileStream2 = new FileStream(text, FileMode.Open, FileAccess.Read, FileShare.Read);

            if (text.IndexOf(".xlsx") > 0)
            {
                workbook = new XSSFWorkbook(fileStream2);
            }
            else if (text.IndexOf(".xls") > 0)
            {
                workbook = new HSSFWorkbook(fileStream2);
            }
            ISheet sheet = null;
            string text3;

            try
            {
                sheet = workbook.GetSheetAt(0);
                string text2 = list[0].Monday.ToString("yyyyMMdd") + "-";
                text2 += list[list.Count - 1].Sunday.ToString("yyyyMMdd");
                text2 += "-";
                Organization organization = ExcelHelper._domainManager.GetOrganization(args.Organization);
                text2 += organization.Name;
                text2 += "-周报";
                sheet.GetRow(0).GetCell(0).SetCellValue(text2);
                ICellStyle cellStyle = workbook.CreateCellStyle();
                cellStyle.BorderBottom      = BorderStyle.Thin;
                cellStyle.BorderLeft        = BorderStyle.Thin;
                cellStyle.BorderRight       = BorderStyle.Thin;
                cellStyle.BorderTop         = BorderStyle.Thin;
                cellStyle.VerticalAlignment = VerticalAlignment.Center;
                cellStyle.WrapText          = true;
                int num = 2;
                foreach (WeeklyReport current2 in list)
                {
                    int firstRow = num;
                    foreach (WeeklyReportItem current3 in current2.ItemList)
                    {
                        IRow expr_1EF = sheet.CreateRow(num);
                        expr_1EF.Height = 350;
                        expr_1EF.CreateCell(0).SetCellValue(current2.Monday.ToString("yyyyMMdd") + "-" + current2.Sunday.ToString("yyyyMMdd"));
                        expr_1EF.CreateCell(1).SetCellValue(current3.OrganizationName);
                        expr_1EF.CreateCell(2).SetCellValue(current2.UserName);
                        expr_1EF.CreateCell(3).SetCellValue(current3.WorkTypeName);
                        expr_1EF.CreateCell(4).SetCellValue(current3.WorkTaskName);
                        expr_1EF.CreateCell(5).SetCellValue(current3.Content.Replace("<br/>", "\r\n"));
                        expr_1EF.CreateCell(6).SetCellValue(current3.StatusName);
                        ICell cell = expr_1EF.CreateCell(7);
                        if (current3.Date.HasValue)
                        {
                            cell.SetCellValue(current3.Date.Value.ToString("yyyy-MM-dd"));
                        }
                        using (List <ICell> .Enumerator enumerator3 = expr_1EF.Cells.GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                enumerator3.Current.CellStyle = cellStyle;
                            }
                        }
                        num++;
                    }
                    CellRangeAddress region = new CellRangeAddress(firstRow, num - 1, 0, 0);
                    sheet.AddMergedRegion(region);
                    region = new CellRangeAddress(firstRow, num - 1, 1, 1);
                    sheet.AddMergedRegion(region);
                    region = new CellRangeAddress(firstRow, num - 1, 2, 2);
                    sheet.AddMergedRegion(region);
                }
                text3      = Path.Combine(rootPath, "ExcelExport", text2 + "(" + DateTime.Now.ToString("ddHHmmss") + ").xls");
                fileStream = new FileStream(text3, FileMode.OpenOrCreate, FileAccess.Write);
                workbook.Write(fileStream);
            }
            catch (Exception arg_3FB_0)
            {
                throw arg_3FB_0;
            }
            finally
            {
                fileStream2.Close();
                fileStream2.Dispose();
                if (fileStream != null)
                {
                    fileStream.Flush();
                    fileStream.Close();
                    fileStream.Dispose();
                }
            }
            return(text3);
        }