コード例 #1
0
            private FileContentResult CreateReport(ReportGeneralModel model)
            {
                string path = Server.MapPath(ConfigurationManager.AppSettings["Excel.Template"]);
                string fileName = String.Format("[{0}] Reporte.xlsx", DateTime.Now.ToString("yyyy-MM-dd"));

                using (Excel xls = new Excel(path))
                {
                    this.CreateReportData(model, xls);

                    MemoryStream ms = new MemoryStream();
                    xls._Workbook.Write(ms);

                    return File(ms.ToArray(), "application/vnd.ms-excel", fileName);
                }
            }
コード例 #2
0
            public ActionResult ReportGeneral(ReportGeneralModel model, bool download = false)
            {
                if (ModelState.IsValid)
                {
                    if (!model.DateStart.HasValue && !model.DateEnd.HasValue && String.IsNullOrEmpty(model.Folder) && String.IsNullOrEmpty(model.Record) && !model.DownloadID.HasValue)
                    {
                        ModelState["DateStart"].Errors.Add("Campo requerido");
                        ModelState["DownloadID"].Errors.Add("Campo requerido");
                    }
                    else
                    {
                        model.Result = this.db.REPORT_GeneralResumen(model.ClientID, model.DateStart, model.DateEnd, model.Folder, model.Record, model.DownloadID).FirstOrDefault();
                        if (model.Result == null)
                        {
                            model.Result = new REPORT_GeneralResumen_Result(){ Imagenes = 0 };
                        }
                    }

                    ViewBag.ClientID = new SelectList(db.Clientes, "CLIID", "CLINombre", model.ClientID);
                }
                else
                {
                    ViewBag.ClientID = new SelectList(db.Clientes, "CLIID", "CLINombre");
                }

                if (download)
                {
                    if (!String.IsNullOrWhiteSpace(model.Result.ReporteURL))
                    {
                        ViewBag.URL = model.Result.ReporteURL;
                        ViewBag.FileName = String.Format("[{0}] Reporte.xlsx", DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                    else
                    {
                        return this.CreateReport(model);
                    }
                }
                return View(model);
            }
コード例 #3
0
            private void CreateReportData(ReportGeneralModel model, Excel xls)
            {
                int rowIndexResume = 2;
                int writeRowIndex = 6;
                int i = 1;

                using (DataSet ds = this.db.REPORT_GeneralDetalle(model.ClientID, model.DateStart, model.DateEnd, model.Folder, model.Record))
                {
                    XSSFRow x = xls.NewRow(rowIndexResume);
                    this.CreateReportResumeRow(x, ds.Tables["Resumen"].Rows[0]);

                    foreach (DataRow row in ds.Tables["Detalle"].Rows)
                    {
                        XSSFRow y = xls.NewRow(writeRowIndex);
                        this.CreateReportDataRow(y, row, i);

                        writeRowIndex++;
                        i++;
                    }
                }
            }