public IActionResult Get(string id)
        {
            try
            {
                using (XTEC_DigitalContext db = new XTEC_DigitalContext())
                {
                    var estudiantes = db.Set <NotasProfesorV>().FromSqlRaw("EXEC VerNotasProfesor {0}", id).ToList();
                    using (var workbook = new XLWorkbook())
                    {
                        var worksheet  = workbook.Worksheets.Add(id);
                        var currentRow = 1;
                        #region Header
                        worksheet.Cell(currentRow, 1).Value = "Carnet";
                        worksheet.Cell(currentRow, 2).Value = "Rubro";
                        worksheet.Cell(currentRow, 3).Value = "Porcentaje Del Rubro";
                        worksheet.Cell(currentRow, 4).Value = "Nombre De Evaluacion";
                        worksheet.Cell(currentRow, 5).Value = "Porcentaje De Evaluacion";
                        worksheet.Cell(currentRow, 6).Value = "Nota";
                        #endregion

                        #region Body
                        foreach (var estudiante in estudiantes)
                        {
                            currentRow++;
                            worksheet.Cell(currentRow, 1).Value = estudiante.Carnet;
                            worksheet.Cell(currentRow, 2).Value = estudiante.Rubro;
                            worksheet.Cell(currentRow, 3).Value = estudiante.PorcentajeDelRubro;
                            worksheet.Cell(currentRow, 4).Value = estudiante.NombreDeEvaluacion;
                            worksheet.Cell(currentRow, 5).Value = estudiante.PorcentajeDeEvaluacion;
                            worksheet.Cell(currentRow, 6).Value = estudiante.Nota;
                        }
                        #endregion

                        using (var stream = new MemoryStream())
                        {
                            workbook.SaveAs(stream);
                            var content = stream.ToArray();

                            return(File(
                                       content,
                                       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                       "NotasEstudiantes.xlsx"
                                       ));
                        }
                    }
                    //return Ok(x);
                }
                //return Ok();
            }
            catch
            {
                return(BadRequest());
            }
        }
Example #2
0
        public IActionResult Get(string id)
        {
            try
            {
                using (XTEC_DigitalContext db = new XTEC_DigitalContext())
                {
                    var estudiantes = db.Set <MatriculadosV>().FromSqlRaw("EXEC VerMatriculados {0}", id).ToList();
                    using (var workbook = new XLWorkbook())
                    {
                        var worksheet  = workbook.Worksheets.Add(id);
                        var currentRow = 1;
                        #region Header
                        worksheet.Cell(currentRow, 1).Value = "Carnet";
                        worksheet.Cell(currentRow, 2).Value = "Nombre";
                        worksheet.Cell(currentRow, 3).Value = "Email";
                        worksheet.Cell(currentRow, 4).Value = "Numero";
                        #endregion

                        #region Body
                        foreach (var estudiante in estudiantes)
                        {
                            currentRow++;
                            worksheet.Cell(currentRow, 1).Value = estudiante.EstudianteId;
                        }
                        #endregion

                        using (var stream = new MemoryStream())
                        {
                            workbook.SaveAs(stream);
                            var content = stream.ToArray();

                            return(File(
                                       content,
                                       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                       "Estudiantes.xlsx"
                                       ));
                        }
                    }
                    //return Ok(x);
                }
                //return Ok();
            }
            catch
            {
                return(BadRequest());
            }
        }