Exemplo n.º 1
0
        public ActionResult ExportOperateLogWithExcel()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = new Worksheet("Sheet1");

            var list = db.T_ZC_MemberLog.ToList();
            foreach (var log in list)
            {
                ExcelGenerator.SpreadSheet.Row row = new ExcelGenerator.SpreadSheet.Row();

                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.ID.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.StartDateTime.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.EndDateTime.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Message.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(Enum.GetName(typeof(OperateTypes),log.OperateType)));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(Enum.GetName(typeof(GenerateSystem),log.GenerateModule)));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.MemberID.ToString()));

                worksheet.Rows.Add(row);
            }
            workbook.Worksheets.Add(worksheet);
            return new ExcelResult(workbook.getBytes(), "Export.xls");
        }
Exemplo n.º 2
0
        public ActionResult ExportErrorLogWithExcel()
        {
            Workbook workbook = new Workbook();
            Worksheet worksheet = new Worksheet("错误日志");

            var list = db.T_ZC_CommonLog.Where(l => l.Level == "Error").ToList();
            foreach( var log in list)
            {
                ExcelGenerator.SpreadSheet.Row row = new ExcelGenerator.SpreadSheet.Row();

                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.ID.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Level.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Logger.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Message.ToString()));
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Source.ToString()));
                if(log.Exception.Length <= 500)
                {
                    row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Exception.ToString()));
                }
                else
                {
                    row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.Exception.Substring(0, 500)));
                }
                row.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(log.User.ToString()));

                worksheet.Rows.Add(row);
            }
            workbook.Worksheets.Add(worksheet);
            return new ExcelResult(workbook.getBytes(), "Export.xls");
        }
Exemplo n.º 3
0
        //returns an XLS Stream
        public static byte[] GetXLS(IList<IList<string>> table)
        {
            //Create a workbook
            Workbook workbook = new Workbook();

            //Create a worksheet
            Worksheet worksheet = new Worksheet("Report");

            //Create a new row
            foreach (var row in table)
            {
                 var xlsRow = new ExcelGenerator.SpreadSheet.Row();
                 foreach (var col in row)
                 {
                     xlsRow.Cells.Add(new ExcelGenerator.SpreadSheet.Cell(col));
                 }
                 worksheet.Rows.Add(xlsRow);
            }

            //Add worksheet to Workbook
            workbook.Worksheets.Add(worksheet);

            return workbook.getBytes();
        }