From 38326246477334e9c39cf8804c95602423552e72 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Wed, 26 Nov 2025 12:24:02 -0300 Subject: [PATCH 01/10] feature: se agrega el metodo nuevo de exportacion a excel --- Business/Business.csproj | 4 + Business/Utility.cs | 196 ++++++++++++++++++++++++++++++++++++--- Business/packages.config | 1 + WebLab/WebLab.csproj | 4 - WebLab/packages.config | 1 - 5 files changed, 189 insertions(+), 17 deletions(-) diff --git a/Business/Business.csproj b/Business/Business.csproj index e7919c36..1d6debc3 100644 --- a/Business/Business.csproj +++ b/Business/Business.csproj @@ -56,6 +56,10 @@ false + + False + ..\packages\EPPlus.4.5.3.3\lib\net40\EPPlus.dll + False ..\Referencias\Iesi.Collections.dll diff --git a/Business/Utility.cs b/Business/Utility.cs index 3baec8ae..3895894a 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Security.Cryptography; using System.Configuration; using System.Xml.Serialization; @@ -14,6 +14,9 @@ //using Sql.Data using System.Security.Cryptography; +using OfficeOpenXml; +using System.Drawing; +using OfficeOpenXml.Style; namespace Business { @@ -599,7 +602,7 @@ public DataTable getDataSet(String strSql, bool conColu) } return ds2.Tables[0]; } - #region " Otros Mtodos " + #region " Otros Métodos " public bool EsNumerico(string val) { @@ -681,12 +684,12 @@ public int VerificaPermisos(ArrayList lista, string m_Objeto) } - /// con - //private const string ConSignos = "u"; + /// con ñ + //private const string ConSignos = "áàäéèëíìïóòöúùuñÁÀÄÉÈËÍÌÏÓÒÖÚÙÜçÇ"; //private const string SinSignos = "aaaeeeiiiooouuunAAAEEEIIIOOOUUUcC"; - /// sin - private const string ConSignos = "uDZ"; + /// sin ñ + private const string ConSignos = "áàäéèëíìïóòöúùuÁÀÄÉÈËÍÌÏÓÒÖÚÙÜçDZ"; private const string SinSignos = "aaaeeeiiiooouuuAAAEEEIIIOOOUUUcCn"; @@ -712,11 +715,11 @@ public bool bisiesto(int anno) bool resultado; //Comprobamos la regla general. //Si anno es divisible por 4, es decir, si el - //resto de la divisin entre 4 es 0... + //resto de la división entre 4 es 0... if (anno % 4 == 0) { //Si es divisible por 4, ahora toca comprobar - //la excepcin + //la excepción if ( (anno % 100 == 0) && //Si es divisible por 100 (anno % 400 != 0) //y no por 400 @@ -726,7 +729,7 @@ public bool bisiesto(int anno) } else { - resultado = true; //No cumple la excepcin. + resultado = true; //No cumple la excepción. //Lo dejamos como bisiesto por ser divisible por 4 } } @@ -792,11 +795,11 @@ public string DiferenciaFechas(DateTime dn, DateTime fechaProtocolo) { ///calculo de fechas teniendo el cuenta los dias de los meses DateTime da = fechaProtocolo; // DateTime.Now; - int anos = da.Year - dn.Year; // calculamos aos + int anos = da.Year - dn.Year; // calculamos años int meses = da.Month - dn.Month; // calculamos meses - int dias = da.Day - dn.Day; // calculamos das + int dias = da.Day - dn.Day; // calculamos días - //ajuste de posible negativo en $das + //ajuste de posible negativo en $días if (dias < 0) { //--$meses; @@ -872,6 +875,175 @@ public void CargarRadioButton(RadioButtonList buttons, String strSql, String Cam + #endregion + + #region Excel + + public static void ExportDataTableToXlsx(DataTable dataTable, string filename) + { + // ⚠️ Si usas EPPlus v5.x o superior, descomenta esta línea: + // OfficeOpenXml.ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial; + + if (dataTable == null || dataTable.Rows.Count == 0) + { + HttpContext.Current.Response.Write("No hay datos para exportar."); + HttpContext.Current.Response.End(); + return; + } + + HttpResponse response = HttpContext.Current.Response; + + // Define el color de fondo por defecto si no se proporciona + // --azul-neuquen: #2b3e4c; + Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen + + using (ExcelPackage package = new ExcelPackage()) + { + // Crear una nueva hoja de trabajo + ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(filename); + + // Cargar la DataTable en la hoja de trabajo. 'true' incluye los encabezados. + worksheet.Cells["A1"].LoadFromDataTable(dataTable, true); + + // --- APLICAR ESTILO AL ENCABEZADO --- + int rowCount = dataTable.Rows.Count; + int colCount = dataTable.Columns.Count; + + // Rango del encabezado: Desde A1 hasta el final de la primera fila + using (var range = worksheet.Cells[1, 1, 1, colCount]) + { + ApplyHeaderStyle(range, finalBackColor); + } + + // Autoajusta las columnas + worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + + // --- CONFIGURAR RESPUESTA HTTP --- + response.Clear(); + response.Buffer = true; + response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + + string fullFilename = filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase) ? filename : filename + ".xlsx"; + response.AddHeader("Content-Disposition", $"attachment; filename=\"{fullFilename}\""); + + // Escribe el paquete de Excel directamente al flujo de salida + package.SaveAs(response.OutputStream); + + response.Flush(); + response.End(); + } + } + + private static void ApplyHeaderStyle(ExcelRange range, Color backColor) + { + range.Style.Font.Bold = true; + range.Style.Fill.PatternType = ExcelFillStyle.Solid; + range.Style.Fill.BackgroundColor.SetColor(backColor); + range.Style.Font.Color.SetColor(Color.White); // Color de fuente blanco (opcional) + } + + public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) + { + using (var package = new ExcelPackage()) + { + var ws = package.Workbook.Worksheets.Add(nombreArchivo); + + int fila = 1; + int col = 1; + + // ================================ + // 1) Escribir encabezados + // ================================ + + + foreach (DataControlField column in grid.Columns) + { + + Color encabezado = grid.HeaderStyle.BackColor; + Color fontColor = grid.HeaderStyle.ForeColor; + + ws.Cells[fila, col].Value = column.HeaderText; + + // Formato encabezado + //Color backgroundColor = ColorTranslator.FromHtml("#2b3e4c"); //Azul Neuquen + ws.Cells[fila, col].Style.Font.Size = 9; + ws.Cells[fila, col].Style.Font.Bold = true; + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(encabezado); + ws.Cells[fila, col].Style.Font.Color.SetColor(fontColor); + ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); + + col++; + } + + fila++; + + // ================================ + // 2) Escribir filas + colores del GridView + // ================================ + foreach (GridViewRow row in grid.Rows) + { + col = 1; + + foreach (TableCell cell in row.Cells) + { + // (2) Decodificar texto HTML + var texto = HttpUtility.HtmlDecode(cell.Text); + + // (1) Detectar si es número + double numero; + bool esNumero = double.TryParse( + texto, + System.Globalization.NumberStyles.Any, + System.Globalization.CultureInfo.InvariantCulture, + out numero + ); + + if (esNumero) + { + ws.Cells[fila, col].Value = numero; + } + else + { + ws.Cells[fila, col].Value = texto; + } + + // Aplicar colores si existen + if (cell.BackColor != Color.Empty) + { + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(cell.BackColor); + } + + if (cell.ForeColor != Color.Empty) + { + ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); + } + + ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); + ws.Cells[fila, col].Style.Font.Size = 9; + col++; + } + + fila++; + } + + // Autoajustar columnas + ws.Cells[1, 1, fila - 1, grid.Columns.Count].AutoFitColumns(); + + // ================================ + // 3) Descargar archivo + // ================================ + var response = HttpContext.Current.Response; + + response.Clear(); + response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + response.AddHeader("content-disposition", $"attachment; filename={nombreArchivo}.xlsx"); + + response.BinaryWrite(package.GetAsByteArray()); + response.End(); + } + } #endregion } } \ No newline at end of file diff --git a/Business/packages.config b/Business/packages.config index 6b05dd43..453e1b88 100644 --- a/Business/packages.config +++ b/Business/packages.config @@ -3,6 +3,7 @@ + diff --git a/WebLab/WebLab.csproj b/WebLab/WebLab.csproj index ca1485e1..a8526f25 100644 --- a/WebLab/WebLab.csproj +++ b/WebLab/WebLab.csproj @@ -162,10 +162,6 @@ False C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet\CrystalDecisions.Web.dll - - ..\packages\EPPlus.7.3.2\lib\net35\EPPlus.dll - True - False bin\fastJSON.dll diff --git a/WebLab/packages.config b/WebLab/packages.config index c75b1bd2..c85104d7 100644 --- a/WebLab/packages.config +++ b/WebLab/packages.config @@ -8,7 +8,6 @@ - From 3f9df851e5445d81752a4e6ebfa2cce576de97bf Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Wed, 26 Nov 2025 13:19:47 -0300 Subject: [PATCH 02/10] fix: formato de fecha --- Business/Utility.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Business/Utility.cs b/Business/Utility.cs index 3895894a..ed595722 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -905,6 +905,22 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) // Cargar la DataTable en la hoja de trabajo. 'true' incluye los encabezados. worksheet.Cells["A1"].LoadFromDataTable(dataTable, true); + // --- FORMATEAR COLUMNAS FECHA --- + for (int col = 0; col < dataTable.Columns.Count; col++) + { + if (dataTable.Columns[col].DataType == typeof(DateTime)) + { + // EPPlus usa 1-based index → sumar 1 + int excelCol = col + 1; + + // aplicar formato "dd/MM/yyyy" + worksheet.Column(excelCol).Style.Numberformat.Format = "dd/MM/yyyy"; + + // opcional: si querés fecha+hora + // worksheet.Column(excelCol).Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; + } + } + // --- APLICAR ESTILO AL ENCABEZADO --- int rowCount = dataTable.Rows.Count; int colCount = dataTable.Columns.Count; From a0fad2f479ebbda025c85a8feb704cb0c3c7618c Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Wed, 26 Nov 2025 13:43:01 -0300 Subject: [PATCH 03/10] fix: para numeros que se pasan como string --- Business/Utility.cs | 63 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/Business/Utility.cs b/Business/Utility.cs index ed595722..55d450fb 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -905,25 +905,68 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) // Cargar la DataTable en la hoja de trabajo. 'true' incluye los encabezados. worksheet.Cells["A1"].LoadFromDataTable(dataTable, true); - // --- FORMATEAR COLUMNAS FECHA --- - for (int col = 0; col < dataTable.Columns.Count; col++) + int colCount = dataTable.Columns.Count; + + // --- ENCABEZADOS --- + for (int c = 0; c < colCount; c++) + { + worksheet.Cells[1, c + 1].Value = dataTable.Columns[c].ColumnName; + } + + // --- DATOS --- + int filaExcel = 2; + + foreach (DataRow row in dataTable.Rows) { - if (dataTable.Columns[col].DataType == typeof(DateTime)) + for (int c = 0; c < colCount; c++) { - // EPPlus usa 1-based index → sumar 1 - int excelCol = col + 1; + object valor = row[c]; + int colExcel = c + 1; - // aplicar formato "dd/MM/yyyy" - worksheet.Column(excelCol).Style.Numberformat.Format = "dd/MM/yyyy"; + // Null o DBNull + if (valor == null || valor == DBNull.Value) + { + worksheet.Cells[filaExcel, colExcel].Value = ""; + continue; + } - // opcional: si querés fecha+hora - // worksheet.Column(excelCol).Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; + // Detectar fechas + if (valor is DateTime dt) + { + worksheet.Cells[filaExcel, colExcel].Value = dt; + worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "dd/MM/yyyy"; + continue; + } + + // Detectar números por TryParse + double numero; + string texto = valor.ToString().Trim(); + + bool esNumero = double.TryParse( + texto, + System.Globalization.NumberStyles.Any, + System.Globalization.CultureInfo.InvariantCulture, + out numero + ); + + if (esNumero) + { + worksheet.Cells[filaExcel, colExcel].Value = numero; + // worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "0.00"; // O "0" + } + else + { + worksheet.Cells[filaExcel, colExcel].Value = texto; + } } + + filaExcel++; } + // --- APLICAR ESTILO AL ENCABEZADO --- int rowCount = dataTable.Rows.Count; - int colCount = dataTable.Columns.Count; + //int colCount = dataTable.Columns.Count; // Rango del encabezado: Desde A1 hasta el final de la primera fila using (var range = worksheet.Cells[1, 1, 1, colCount]) From 549fa4703a090a7ea22951812fee19a55c2ec7f8 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:53:01 -0300 Subject: [PATCH 04/10] fix: exportar decimales --- Business/Utility.cs | 343 +++++++++++++++++++++++--------------------- 1 file changed, 182 insertions(+), 161 deletions(-) diff --git a/Business/Utility.cs b/Business/Utility.cs index 55d450fb..e7e3cb91 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -884,113 +884,111 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) // ⚠️ Si usas EPPlus v5.x o superior, descomenta esta línea: // OfficeOpenXml.ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial; - if (dataTable == null || dataTable.Rows.Count == 0) + if (dataTable.Rows.Count > 0) { - HttpContext.Current.Response.Write("No hay datos para exportar."); - HttpContext.Current.Response.End(); - return; - } - - HttpResponse response = HttpContext.Current.Response; - - // Define el color de fondo por defecto si no se proporciona - // --azul-neuquen: #2b3e4c; - Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen - - using (ExcelPackage package = new ExcelPackage()) - { - // Crear una nueva hoja de trabajo - ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(filename); - // Cargar la DataTable en la hoja de trabajo. 'true' incluye los encabezados. - worksheet.Cells["A1"].LoadFromDataTable(dataTable, true); + HttpResponse response = HttpContext.Current.Response; - int colCount = dataTable.Columns.Count; + // Define el color de fondo por defecto si no se proporciona + // --azul-neuquen: #2b3e4c; + Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen - // --- ENCABEZADOS --- - for (int c = 0; c < colCount; c++) + using (ExcelPackage package = new ExcelPackage()) { - worksheet.Cells[1, c + 1].Value = dataTable.Columns[c].ColumnName; - } + // Crear una nueva hoja de trabajo + ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(filename); - // --- DATOS --- - int filaExcel = 2; + // Cargar la DataTable en la hoja de trabajo. 'true' incluye los encabezados. + worksheet.Cells["A1"].LoadFromDataTable(dataTable, true); - foreach (DataRow row in dataTable.Rows) - { + int colCount = dataTable.Columns.Count; + + // --- ENCABEZADOS --- for (int c = 0; c < colCount; c++) { - object valor = row[c]; - int colExcel = c + 1; + worksheet.Cells[1, c + 1].Value = dataTable.Columns[c].ColumnName; + } - // Null o DBNull - if (valor == null || valor == DBNull.Value) - { - worksheet.Cells[filaExcel, colExcel].Value = ""; - continue; - } + // --- DATOS --- + int filaExcel = 2; - // Detectar fechas - if (valor is DateTime dt) + foreach (DataRow row in dataTable.Rows) + { + for (int c = 0; c < colCount; c++) { - worksheet.Cells[filaExcel, colExcel].Value = dt; - worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "dd/MM/yyyy"; - continue; + object valor = row[c]; + int colExcel = c + 1; + + // Null o DBNull + if (valor == null || valor == DBNull.Value) + { + worksheet.Cells[filaExcel, colExcel].Value = ""; + continue; + } + + // Detectar fechas + if (valor is DateTime dt) + { + worksheet.Cells[filaExcel, colExcel].Value = dt; + worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "dd/MM/yyyy"; + continue; + } + + // Detectar números por TryParse + double numero; + string texto = valor.ToString().Trim(); + + bool esNumero = double.TryParse( + texto, + System.Globalization.NumberStyles.Any, + System.Globalization.CultureInfo.InvariantCulture, + out numero + ); + + if (esNumero) + { + worksheet.Cells[filaExcel, colExcel].Value = numero; + // worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "0.00"; // O "0" + } + else + { + worksheet.Cells[filaExcel, colExcel].Value = texto; + } } - // Detectar números por TryParse - double numero; - string texto = valor.ToString().Trim(); - - bool esNumero = double.TryParse( - texto, - System.Globalization.NumberStyles.Any, - System.Globalization.CultureInfo.InvariantCulture, - out numero - ); - - if (esNumero) - { - worksheet.Cells[filaExcel, colExcel].Value = numero; - // worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "0.00"; // O "0" - } - else - { - worksheet.Cells[filaExcel, colExcel].Value = texto; - } + filaExcel++; } - filaExcel++; - } - - // --- APLICAR ESTILO AL ENCABEZADO --- - int rowCount = dataTable.Rows.Count; - //int colCount = dataTable.Columns.Count; + // --- APLICAR ESTILO AL ENCABEZADO --- + int rowCount = dataTable.Rows.Count; + //int colCount = dataTable.Columns.Count; - // Rango del encabezado: Desde A1 hasta el final de la primera fila - using (var range = worksheet.Cells[1, 1, 1, colCount]) - { - ApplyHeaderStyle(range, finalBackColor); - } + // Rango del encabezado: Desde A1 hasta el final de la primera fila + using (var range = worksheet.Cells[1, 1, 1, colCount]) + { + ApplyHeaderStyle(range, finalBackColor); + } - // Autoajusta las columnas - worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + // Autoajusta las columnas + worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); - // --- CONFIGURAR RESPUESTA HTTP --- - response.Clear(); - response.Buffer = true; - response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + // --- CONFIGURAR RESPUESTA HTTP --- + response.Clear(); + response.Buffer = true; + response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - string fullFilename = filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase) ? filename : filename + ".xlsx"; - response.AddHeader("Content-Disposition", $"attachment; filename=\"{fullFilename}\""); + string fullFilename = filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase) ? filename : filename + ".xlsx"; + response.AddHeader("Content-Disposition", $"attachment; filename=\"{fullFilename}\""); - // Escribe el paquete de Excel directamente al flujo de salida - package.SaveAs(response.OutputStream); + // Escribe el paquete de Excel directamente al flujo de salida + package.SaveAs(response.OutputStream); - response.Flush(); - response.End(); + response.Flush(); + response.End(); + } } + } private static void ApplyHeaderStyle(ExcelRange range, Color backColor) @@ -1003,104 +1001,127 @@ private static void ApplyHeaderStyle(ExcelRange range, Color backColor) public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) { - using (var package = new ExcelPackage()) + if(grid.Rows.Count > 0) { - var ws = package.Workbook.Worksheets.Add(nombreArchivo); - - int fila = 1; - int col = 1; - - // ================================ - // 1) Escribir encabezados - // ================================ - - - foreach (DataControlField column in grid.Columns) + using (var package = new ExcelPackage()) { + var ws = package.Workbook.Worksheets.Add(nombreArchivo); - Color encabezado = grid.HeaderStyle.BackColor; - Color fontColor = grid.HeaderStyle.ForeColor; + int fila = 1; + int col = 1; - ws.Cells[fila, col].Value = column.HeaderText; + // ================================ + // 1) Escribir encabezados + // ================================ - // Formato encabezado - //Color backgroundColor = ColorTranslator.FromHtml("#2b3e4c"); //Azul Neuquen - ws.Cells[fila, col].Style.Font.Size = 9; - ws.Cells[fila, col].Style.Font.Bold = true; - ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; - ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(encabezado); - ws.Cells[fila, col].Style.Font.Color.SetColor(fontColor); - ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); + Color encabezadoColor = grid.HeaderStyle.BackColor; + Color fontColor = grid.HeaderStyle.ForeColor; - col++; - } + if (encabezadoColor == fontColor) + { + encabezadoColor = Color.White; + fontColor = Color.Black; + } + foreach (DataControlField column in grid.Columns) + { + ws.Cells[fila, col].Value = column.HeaderText; + ws.Cells[fila, col].Style.Font.Size = 9; + ws.Cells[fila, col].Style.Font.Bold = true; + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(encabezadoColor); + ws.Cells[fila, col].Style.Font.Color.SetColor(fontColor); + ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); - fila++; + col++; + } - // ================================ - // 2) Escribir filas + colores del GridView - // ================================ - foreach (GridViewRow row in grid.Rows) - { - col = 1; + fila++; - foreach (TableCell cell in row.Cells) + // ================================ + // 2) Escribir filas + colores del GridView + // ================================ + foreach (GridViewRow row in grid.Rows) { - // (2) Decodificar texto HTML - var texto = HttpUtility.HtmlDecode(cell.Text); - - // (1) Detectar si es número - double numero; - bool esNumero = double.TryParse( - texto, - System.Globalization.NumberStyles.Any, - System.Globalization.CultureInfo.InvariantCulture, - out numero - ); - - if (esNumero) - { - ws.Cells[fila, col].Value = numero; - } - else - { - ws.Cells[fila, col].Value = texto; - } - - // Aplicar colores si existen - if (cell.BackColor != Color.Empty) - { - ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; - ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(cell.BackColor); - } + col = 1; - if (cell.ForeColor != Color.Empty) + foreach (TableCell cell in row.Cells) { - ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); + // (2) Decodificar texto HTML + var texto = HttpUtility.HtmlDecode(cell.Text); + + // (1) Detectar si es número + double numero; + bool esNumero = double.TryParse( + texto, + System.Globalization.NumberStyles.Any, + System.Globalization.CultureInfo.GetCultureInfo("es-ES"), // Usar una cultura que use la coma como separador decimal + out numero + ); + + if (esNumero) + { + ws.Cells[fila, col].Value = numero; + } + else + { + ws.Cells[fila, col].Value = texto; + } + + // Aplicar colores si existen + + + if (cell.BackColor != Color.Empty) + { + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(cell.BackColor); + } + + if (cell.ForeColor != Color.Empty) + { + ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); + } + + + + ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); + ws.Cells[fila, col].Style.Font.Size = 9; + //ws.Cells[fila, col].Style.WrapText = true; //Ajusta texto largo en la celda + col++; } - ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); - ws.Cells[fila, col].Style.Font.Size = 9; - col++; + fila++; } - fila++; - } + // Autoajustar columnas + ws.Cells[1, 1, fila - 1, grid.Columns.Count].AutoFitColumns(); - // Autoajustar columnas - ws.Cells[1, 1, fila - 1, grid.Columns.Count].AutoFitColumns(); + // ================================ + // 3) Descargar archivo + // ================================ + var response = HttpContext.Current.Response; - // ================================ - // 3) Descargar archivo - // ================================ - var response = HttpContext.Current.Response; + response.Clear(); + response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + response.AddHeader("content-disposition", $"attachment; filename={nombreArchivo}.xlsx"); - response.Clear(); - response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - response.AddHeader("content-disposition", $"attachment; filename={nombreArchivo}.xlsx"); + response.BinaryWrite(package.GetAsByteArray()); + response.End(); + } + } + + } - response.BinaryWrite(package.GetAsByteArray()); - response.End(); + public static void GenerarColumnasGrid(GridView grid, DataTable dt) + { + if(dt.Columns.Count > 0) + { + DataColumnCollection dc = dt.Columns; + foreach(DataColumn column in dc) + { + BoundField columna = new BoundField(); + columna.HeaderText = column.ColumnName; + grid.Columns.Add(columna); + } } } #endregion From 5703c97c6bbf8daae17bb1a1f56a861786be1a46 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Thu, 27 Nov 2025 11:09:31 -0300 Subject: [PATCH 05/10] fix: correcion de culture en decimales --- Business/Utility.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Business/Utility.cs b/Business/Utility.cs index e7e3cb91..1d04fcd0 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -941,14 +941,13 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) bool esNumero = double.TryParse( texto, System.Globalization.NumberStyles.Any, - System.Globalization.CultureInfo.InvariantCulture, + System.Globalization.CultureInfo.GetCultureInfo("es-ES"), // Usar una cultura que use la coma como separador decimal out numero ); if (esNumero) { worksheet.Cells[filaExcel, colExcel].Value = numero; - // worksheet.Cells[filaExcel, colExcel].Style.Numberformat.Format = "0.00"; // O "0" } else { From 8c090e31258171d5b4785323931d71859b282047 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Thu, 27 Nov 2025 15:00:38 -0300 Subject: [PATCH 06/10] feature: cambios de excel --- WebLab/Derivaciones/LoteList.aspx.cs | 48 +- .../EstadisticaResultadoTexto.aspx.cs | 51 +- WebLab/Estadisticas/Produccion.aspx.cs | 50 +- WebLab/Estadisticas/Reporte.aspx | 2 +- WebLab/Estadisticas/Reporte.aspx.cs | 115 ++-- .../Estadisticas/ReporteIncidencias.aspx.cs | 160 ++--- .../Estadisticas/ReporteMicrobiologia.aspx.cs | 596 +++++++++--------- .../ReporteMicrobiologiaNoPaciente.aspx.cs | 102 +-- .../Estadisticas/ReportePorResultado.aspx.cs | 96 +-- .../ReportePorResultadoNum.aspx.cs | 61 +- .../ReportePorResultadoTexto.aspx.cs | 45 +- WebLab/Estadisticas/Turnos.aspx.cs | 51 +- WebLab/Items/ItemList.aspx.cs | 45 +- WebLab/Protocolos/ProtocoloExport.aspx.cs | 57 +- WebLab/Protocolos/ProtocoloList.aspx.cs | 45 +- .../Protocolos/ProtocoloListForense.aspx.cs | 45 +- WebLab/Seguimiento.aspx.cs | 46 +- WebLab/SeguimientoDerivaciones.aspx.cs | 53 +- WebLab/SeguimientoIncidencias.aspx.cs | 53 +- WebLab/SeguimientoResultados.aspx.cs | 44 +- WebLab/SeguimientoResultadosSemanal.aspx.cs | 43 +- 21 files changed, 930 insertions(+), 878 deletions(-) diff --git a/WebLab/Derivaciones/LoteList.aspx.cs b/WebLab/Derivaciones/LoteList.aspx.cs index 3f06378a..1d537289 100644 --- a/WebLab/Derivaciones/LoteList.aspx.cs +++ b/WebLab/Derivaciones/LoteList.aspx.cs @@ -469,30 +469,32 @@ protected void lnkExcel_Click(object sender, EventArgs e) tabla.Columns["fechaIngreso"].ColumnName = "Fecha Ing."; tabla.Columns["fechaEnvio"].ColumnName = "Fecha Envio"; - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - Page pagina = new Page(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); Utility oUtil = new Utility(); - string nombrXLS = oUtil.CompletarNombrePDF("Lotes"); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombrXLS + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, oUtil.CompletarNombrePDF("Lotes")); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //Page pagina = new Page(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Utility oUtil = new Utility(); + //string nombrXLS = oUtil.CompletarNombrePDF("Lotes"); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombrXLS + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } else { diff --git a/WebLab/Estadisticas/EstadisticaResultadoTexto.aspx.cs b/WebLab/Estadisticas/EstadisticaResultadoTexto.aspx.cs index 88ac67a0..db41db22 100644 --- a/WebLab/Estadisticas/EstadisticaResultadoTexto.aspx.cs +++ b/WebLab/Estadisticas/EstadisticaResultadoTexto.aspx.cs @@ -334,31 +334,32 @@ private void ExportarExcel(DataTable tabla) if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=Estadisticas_"+ oUser.IdEfector.Nombre+"_"+ DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); - } + Utility.ExportDataTableToXlsx(tabla, "Estadisticas_"+ oUser.IdEfector.Nombre+"_"+ DateTime.Now.ToShortDateString() ); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=Estadisticas_"+ oUser.IdEfector.Nombre+"_"+ DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); + } else { diff --git a/WebLab/Estadisticas/Produccion.aspx.cs b/WebLab/Estadisticas/Produccion.aspx.cs index 3b81f9a1..cb5171a8 100644 --- a/WebLab/Estadisticas/Produccion.aspx.cs +++ b/WebLab/Estadisticas/Produccion.aspx.cs @@ -164,7 +164,8 @@ private void ImprimirReporteAgrupado() gvEstadistica.DataSource = dt; gvEstadistica.DataBind(); - StringBuilder sb = new StringBuilder(); + Utility.ExportGridViewToExcel(gvEstadistica, "estadisticaProduccionTotal"); + /* StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HtmlTextWriter htw = new HtmlTextWriter(sw); @@ -188,7 +189,7 @@ private void ImprimirReporteAgrupado() Response.Charset = "UTF-8"; Response.ContentEncoding = Encoding.Default; Response.Write(sb.ToString()); - Response.End(); + Response.End(); */ //ExcelPackage.LicenseContext = LicenseContext.NonCommercial; //using (var package = new ExcelPackage()) //{ @@ -452,28 +453,29 @@ private void dataTableAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + "_" + oUser.IdEfector.IdEfector2 + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo + "_" + oUser.IdEfector.IdEfector2); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + "_" + oUser.IdEfector.IdEfector2 + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } //private void dataTableAExcel(DataTable tabla, string nombreArchivo) diff --git a/WebLab/Estadisticas/Reporte.aspx b/WebLab/Estadisticas/Reporte.aspx index ff83802f..c4818dbe 100644 --- a/WebLab/Estadisticas/Reporte.aspx +++ b/WebLab/Estadisticas/Reporte.aspx @@ -39,7 +39,7 @@ Descargar Detalle Por Deteterminacion + >Descargar Detalle Por Determinacion  
diff --git a/WebLab/Estadisticas/Reporte.aspx.cs b/WebLab/Estadisticas/Reporte.aspx.cs index fd7a9b2c..87b25b04 100644 --- a/WebLab/Estadisticas/Reporte.aspx.cs +++ b/WebLab/Estadisticas/Reporte.aspx.cs @@ -19,6 +19,7 @@ using CrystalDecisions.Web; using System.Text; using Business.Data; +using System.Collections.Generic; namespace WebLab.Estadisticas { @@ -51,7 +52,6 @@ protected void Page_PreInit(object sender, EventArgs e) oUser = (Usuario)oUser.Get(typeof(Usuario), int.Parse(Session["idUsuario"].ToString())); } - } protected void Page_Load(object sender, EventArgs e) { @@ -70,9 +70,11 @@ protected void Page_Load(object sender, EventArgs e) // MostrarReporteGeneral(); if (Session["informe"].ToString() == "PorResultado") MostrarInformePorResultado("Pantalla"); + } - + } + } protected void Page_Unload(object sender, EventArgs e) { @@ -541,10 +543,10 @@ private DataTable GetDatosEstadistica(string s_tipo) - - if (lblTipo.Text == "5") Ds.Tables[0].Rows.Add(); - + + if (lblTipo.Text == "5") Ds.Tables[0].Rows.Add(); + return Ds.Tables[0]; } @@ -774,33 +776,34 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcel() { - - - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvEstadistica.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvEstadistica); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=estadistica.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.GenerarColumnasGrid(gvEstadistica, gvEstadistica.DataSource as DataTable); + Utility.ExportGridViewToExcel(gvEstadistica, "estadistica"); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //|.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvEstadistica); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=estadistica.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void lnkDetallePorDet_Click(object sender, EventArgs e) @@ -849,29 +852,33 @@ private void dETALLEAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + "_" + oUser.IdEfector.IdEfector2 + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo + "_" + oUser.IdEfector.IdEfector2); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + "_" + oUser.IdEfector.IdEfector2 + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } + } + + } } diff --git a/WebLab/Estadisticas/ReporteIncidencias.aspx.cs b/WebLab/Estadisticas/ReporteIncidencias.aspx.cs index de116627..1392e87e 100644 --- a/WebLab/Estadisticas/ReporteIncidencias.aspx.cs +++ b/WebLab/Estadisticas/ReporteIncidencias.aspx.cs @@ -197,31 +197,33 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcel(string nombreArchivo) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView1.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(GridView1); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(GridView1, nombreArchivo); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView1.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(GridView1); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcel0_Click(object sender, ImageClickEventArgs e) @@ -231,31 +233,32 @@ protected void imgExcel0_Click(object sender, ImageClickEventArgs e) private void ExportarExcel2(string p) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvProtocolos.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvProtocolos); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + p + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvProtocolos, p); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvProtocolos.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvProtocolos); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + p + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) @@ -318,34 +321,35 @@ protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) protected void btnDetalleProtocolos_Click(object sender, EventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = LeerIncidencias("2"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=ProtocolosIncidencias.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(LeerIncidencias("2"), "ProtocolosIncidencias"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = LeerIncidencias("2"); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=ProtocolosIncidencias.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } \ No newline at end of file diff --git a/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs b/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs index 4a72bc94..5951fff4 100644 --- a/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs +++ b/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs @@ -535,31 +535,32 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcelTipoMuestra() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvTipoMuestra.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvTipoMuestra); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_TipoMuestra.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvTipoMuestra, ddlAnalisis.SelectedItem.Text + "_TipoMuestra"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvTipoMuestra.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvTipoMuestra); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_TipoMuestra.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void ddlAnalisis_SelectedIndexChanged(object sender, EventArgs e) @@ -593,31 +594,32 @@ protected void imgExcel0_Click(object sender, ImageClickEventArgs e) private void ExportarExcelMicroorganismos() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvMicroorganismos.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvMicroorganismos); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Microorganismos.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvMicroorganismos, ddlAnalisis.SelectedItem.Text + "_Microorganismos"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvMicroorganismos.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvMicroorganismos); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Microorganismos.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcel1_Click(object sender, ImageClickEventArgs e) @@ -627,31 +629,32 @@ protected void imgExcel1_Click(object sender, ImageClickEventArgs e) private void ExportarExcelAntibioticos() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvAntibiotico.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvAntibiotico); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Antibiotico.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvAntibiotico, ddlAnalisis.SelectedItem.Text + "_Antibiotico"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvAntibiotico.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvAntibiotico); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Antibiotico.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcel2_Click(object sender, ImageClickEventArgs e) @@ -661,31 +664,32 @@ protected void imgExcel2_Click(object sender, ImageClickEventArgs e) private void ExportarExcelResultados() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvResultado.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvResultado); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Resultado.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvResultado, ddlAnalisis.SelectedItem.Text + "_Resultado"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvResultado.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvResultado); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Resultado.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void gvTipoMuestra_RowDataBound(object sender, GridViewRowEventArgs e) @@ -955,34 +959,36 @@ protected void gvAntibioticoResistencia_RowDataBound(object sender, GridViewRowE protected void btnDescargarDetallePacientes_Click(object sender, EventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("General"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Pacientes.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + + Utility.ExportDataTableToXlsx(GetDataPacientes("General"), ddlAnalisis.SelectedItem.Text + "_Pacientes"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("General"); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Pacientes.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void gvResultado_RowCommand(object sender, GridViewCommandEventArgs e) @@ -1156,130 +1162,138 @@ INNER JOIN Mecanismos Mec protected void imgExcelResultadoPacientes_Click1(object sender, ImageClickEventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("Resultado"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text+ "_Resultados.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + + Utility.ExportDataTableToXlsx(GetDataPacientes("Resultado"), ddlAnalisis.SelectedItem.Text + "_Resultados"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("Resultado"); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text+ "_Resultados.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcelDetallePacientes_Click(object sender, ImageClickEventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("General"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Pacientes.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + + Utility.ExportDataTableToXlsx(GetDataPacientes("General"), ddlAnalisis.SelectedItem.Text + "_Pacientes"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("General"); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Pacientes.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcelDetallePacientesAislamientos_Click(object sender, ImageClickEventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("Aislamiento"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text.Trim() + "_Pacientes.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + + Utility.ExportDataTableToXlsx(GetDataPacientes("Aislamiento"), ddlAnalisis.SelectedItem.Text + "_Pacientes"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("Aislamiento"); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text.Trim() + "_Pacientes.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgExcelDetalleAtb_Click(object sender, ImageClickEventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("ATB"); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + + Utility.ExportDataTableToXlsx(GetDataPacientes("ATB"), ddlAnalisis.SelectedItem.Text); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("ATB"); + //dg.DataBind(); + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } @@ -1410,64 +1424,68 @@ protected void imgExcelMecanismo_Click(object sender, ImageClickEventArgs e) private void ExportarExcelMecanismo() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - - gvTipoMecanismo.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvTipoMecanismo); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Mecanismo.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvTipoMecanismo, ddlAnalisis.SelectedItem.Text); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + + //gvTipoMecanismo.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvTipoMecanismo); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Mecanismo.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void imgPacientesMecanismo_Click(object sender, ImageClickEventArgs e) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); GridView dg = new GridView(); dg.EnableViewState = false; dg.DataSource = GetDataPacientes("Mecanismo"); dg.DataBind(); + Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); + Utility.ExportGridViewToExcel(dg, ddlAnalisis.SelectedItem.Text + "_Mecanismo"); + // StringBuilder sb = new StringBuilder(); + // StringWriter sw = new StringWriter(sb); + // HtmlTextWriter htw = new HtmlTextWriter(sw); + + // Page page = new Page(); + // HtmlForm form = new HtmlForm(); + - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Mecanismo.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + // // Deshabilitar la validación de eventos, sólo asp.net 2 + // page.EnableEventValidation = false; + + // // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + // page.DesignerInitialize(); + // page.Controls.Add(form); + // form.Controls.Add(dg); + // page.RenderControl(htw); + + // Response.Clear(); + // Response.Buffer = true; + // Response.ContentType = "application/vnd.ms-excel"; + // Response.AddHeader("Content-Disposition", "attachment;filename=" + ddlAnalisis.SelectedItem.Text + "_Mecanismo.xls"); + // Response.Charset = "UTF-8"; + // Response.ContentEncoding = Encoding.Default; + // Response.Write(sb.ToString()); + // Response.End(); } } } diff --git a/WebLab/Estadisticas/ReporteMicrobiologiaNoPaciente.aspx.cs b/WebLab/Estadisticas/ReporteMicrobiologiaNoPaciente.aspx.cs index b8c9b174..476c1c6e 100644 --- a/WebLab/Estadisticas/ReporteMicrobiologiaNoPaciente.aspx.cs +++ b/WebLab/Estadisticas/ReporteMicrobiologiaNoPaciente.aspx.cs @@ -376,31 +376,32 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcelTipoMuestra() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvTipoMuestra.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvTipoMuestra); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=NoPaciente_TipoMuestra.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvTipoMuestra, "NoPaciente_TipoMuestra"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvTipoMuestra.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvTipoMuestra); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=NoPaciente_TipoMuestra.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void ddlAnalisis_SelectedIndexChanged(object sender, EventArgs e) @@ -448,31 +449,32 @@ protected void imgExcel2_Click(object sender, ImageClickEventArgs e) private void ExportarExcelResultados() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvResultado.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvResultado); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=_Resultado.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvResultado, "NoPaciente_Resultado"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvResultado.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvResultado); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=_Resultado.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void gvTipoMuestra_RowDataBound(object sender, GridViewRowEventArgs e) diff --git a/WebLab/Estadisticas/ReportePorResultado.aspx.cs b/WebLab/Estadisticas/ReportePorResultado.aspx.cs index 2650203f..f5147d40 100644 --- a/WebLab/Estadisticas/ReportePorResultado.aspx.cs +++ b/WebLab/Estadisticas/ReportePorResultado.aspx.cs @@ -456,28 +456,30 @@ private void ExportarExcel() DataTable tabla= GetDatosEstadistica("GV"); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + lblAnalisis.Text + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, lblAnalisis.Text); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + lblAnalisis.Text + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } @@ -576,33 +578,35 @@ private void InformePacientes(string p, string reporte) } if (reporte == "EXCEL") { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes(m_analisis, m_resultado, int.Parse(ddlEfector.SelectedValue), "EXCEL"); - dg.DataBind(); + Utility.ExportDataTableToXlsx(GetDataPacientes(m_analisis, m_resultado, int.Parse(ddlEfector.SelectedValue), "EXCEL"), "DetallePacientes"); + + // StringBuilder sb = new StringBuilder(); + // StringWriter sw = new StringWriter(sb); + // HtmlTextWriter htw = new HtmlTextWriter(sw); + + // Page page = new Page(); + // HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes(m_analisis, m_resultado, int.Parse(ddlEfector.SelectedValue), "EXCEL"); + //dg.DataBind(); // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; + // page.EnableEventValidation = false; // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=DetallePacientes.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + //page.DesignerInitialize(); + // page.Controls.Add(form); + // form.Controls.Add(dg); + // page.RenderControl(htw); + + // Response.Clear(); + // Response.Buffer = true; + // Response.ContentType = "application/vnd.ms-excel"; + // Response.AddHeader("Content-Disposition", "attachment;filename=DetallePacientes.xls"); + // Response.Charset = "UTF-8"; + // Response.ContentEncoding = Encoding.Default; + // Response.Write(sb.ToString()); + // Response.End(); } } diff --git a/WebLab/Estadisticas/ReportePorResultadoNum.aspx.cs b/WebLab/Estadisticas/ReportePorResultadoNum.aspx.cs index a964b9a5..02526017 100644 --- a/WebLab/Estadisticas/ReportePorResultadoNum.aspx.cs +++ b/WebLab/Estadisticas/ReportePorResultadoNum.aspx.cs @@ -274,7 +274,8 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcel() { - StringBuilder sb = new StringBuilder(); + Utility.ExportGridViewToExcel(gvEstadistica, "reporteresultados"); + /*StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); HtmlTextWriter htw = new HtmlTextWriter(sw); @@ -298,7 +299,7 @@ private void ExportarExcel() Response.Charset = "UTF-8"; Response.ContentEncoding = Encoding.Default; Response.Write(sb.ToString()); - Response.End(); + Response.End();*/ } protected void ddlAnalisis_SelectedIndexChanged(object sender, EventArgs e) @@ -410,33 +411,35 @@ private void InformePacientes(string p, string reporte) } if (reporte == "EXCEL") { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes(m_analisis, m_sexo.Substring(0, 1), txtValorDesde.Text, txtValorHasta.Text, int.Parse(ddlEfector.SelectedValue)); - dg.DataBind(); - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=DetallePacientes.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + DataTable dt = GetDataPacientes(m_analisis, m_sexo.Substring(0, 1), txtValorDesde.Text, txtValorHasta.Text, int.Parse(ddlEfector.SelectedValue)); + Utility.ExportDataTableToXlsx(dt, "DetallePacientes"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes(m_analisis, m_sexo.Substring(0, 1), txtValorDesde.Text, txtValorHasta.Text, int.Parse(ddlEfector.SelectedValue)); + //dg.DataBind(); + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=DetallePacientes.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/Estadisticas/ReportePorResultadoTexto.aspx.cs b/WebLab/Estadisticas/ReportePorResultadoTexto.aspx.cs index e033e900..3d69ca6b 100644 --- a/WebLab/Estadisticas/ReportePorResultadoTexto.aspx.cs +++ b/WebLab/Estadisticas/ReportePorResultadoTexto.aspx.cs @@ -473,28 +473,29 @@ private void ExportarExcel() DataTable tabla= GetDatosEstadistica("GV"); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=Estadistica.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "Estadistica"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=Estadistica.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } diff --git a/WebLab/Estadisticas/Turnos.aspx.cs b/WebLab/Estadisticas/Turnos.aspx.cs index cca1e723..846275aa 100644 --- a/WebLab/Estadisticas/Turnos.aspx.cs +++ b/WebLab/Estadisticas/Turnos.aspx.cs @@ -248,31 +248,32 @@ protected void imgPdf_Click(object sender, ImageClickEventArgs e) private void ExportarExcel() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvLista.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvLista); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=estadistica_turnos.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(getDatosEstadisticos("G"), "estadistica_turnos"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvLista.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvLista); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=estadistica_turnos.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } private void MostrarPDF() { diff --git a/WebLab/Items/ItemList.aspx.cs b/WebLab/Items/ItemList.aspx.cs index 73ffdece..c48e91a1 100644 --- a/WebLab/Items/ItemList.aspx.cs +++ b/WebLab/Items/ItemList.aspx.cs @@ -568,28 +568,29 @@ private void dataTableAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/Protocolos/ProtocoloExport.aspx.cs b/WebLab/Protocolos/ProtocoloExport.aspx.cs index b85020e9..528bd421 100644 --- a/WebLab/Protocolos/ProtocoloExport.aspx.cs +++ b/WebLab/Protocolos/ProtocoloExport.aspx.cs @@ -301,34 +301,35 @@ private void ExportarExcel() if (Request["idServicio"].ToString() == "3") s_nombreArchivo = "Microbiologia_"+DateTime.Now.ToShortDateString().Replace("/",""); else s_nombreArchivo = "Laboratorio_" + DateTime.Now.ToShortDateString().Replace("/", ""); - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GenerarSetDatos(); - dg.DataBind(); - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(dg); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename="+s_nombreArchivo+".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(GenerarSetDatos(), s_nombreArchivo); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GenerarSetDatos(); + //dg.DataBind(); + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(dg); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename="+s_nombreArchivo+".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } protected void lnkExportar_Click(object sender, EventArgs e) diff --git a/WebLab/Protocolos/ProtocoloList.aspx.cs b/WebLab/Protocolos/ProtocoloList.aspx.cs index f73afc08..bc4a85a4 100644 --- a/WebLab/Protocolos/ProtocoloList.aspx.cs +++ b/WebLab/Protocolos/ProtocoloList.aspx.cs @@ -1421,28 +1421,29 @@ private void dataTableAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } diff --git a/WebLab/Protocolos/ProtocoloListForense.aspx.cs b/WebLab/Protocolos/ProtocoloListForense.aspx.cs index 0f0daffb..b44270ce 100644 --- a/WebLab/Protocolos/ProtocoloListForense.aspx.cs +++ b/WebLab/Protocolos/ProtocoloListForense.aspx.cs @@ -1117,28 +1117,29 @@ private void dataTableAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } diff --git a/WebLab/Seguimiento.aspx.cs b/WebLab/Seguimiento.aspx.cs index f8b264bc..a6b87e17 100644 --- a/WebLab/Seguimiento.aspx.cs +++ b/WebLab/Seguimiento.aspx.cs @@ -199,7 +199,7 @@ inner JOIN LAB_DetalleProtocolo DP with (nolock) ON DP.idProtocolo = IR.idProtoc where DP.idsubitem in ( " + GetDeterminaciones() +") "+ m_strSQLCondicion + @" and ir.baja=0 -order by ir.numero + "; @@ -208,8 +208,8 @@ order by ir.numero from (" + m_strSQL + @" AND IR.IDPACIENTE>-1)x group by [Tipo Doc.], [Nro. Documento], Apellido, [Nombre], [Fecha Nacimiento], [Sexo]"; - - + else + m_strSQL += " order by ir.numero"; DataSet Ds = new DataSet(); SqlConnection conn = (SqlConnection)NHibernateHttpModule.CurrentSession.Connection; SqlDataAdapter adapter = new SqlDataAdapter(); @@ -258,11 +258,11 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(oItem); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); GridView dg = new GridView(); dg.EnableViewState = false; dg.DataSource = tabla; @@ -271,20 +271,22 @@ private void ExportarExcel() dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); } dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=Seguimiento_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); + Utility.ExportGridViewToExcel(dg, "Seguimiento_" + DateTime.Now.ToShortDateString()); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + ////Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=Seguimiento_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/SeguimientoDerivaciones.aspx.cs b/WebLab/SeguimientoDerivaciones.aspx.cs index cabe1812..2db9ede2 100644 --- a/WebLab/SeguimientoDerivaciones.aspx.cs +++ b/WebLab/SeguimientoDerivaciones.aspx.cs @@ -200,32 +200,33 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Derivaciones_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "CodVid_Derivaciones_" + DateTime.Now.ToShortDateString() ); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); + + + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Derivaciones_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } catch diff --git a/WebLab/SeguimientoIncidencias.aspx.cs b/WebLab/SeguimientoIncidencias.aspx.cs index a89de816..85053da7 100644 --- a/WebLab/SeguimientoIncidencias.aspx.cs +++ b/WebLab/SeguimientoIncidencias.aspx.cs @@ -165,32 +165,33 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(oItem); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Incidencias_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "CodVid_Incidencias_" + DateTime.Now.ToShortDateString() ); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); + + + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Incidencias_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/SeguimientoResultados.aspx.cs b/WebLab/SeguimientoResultados.aspx.cs index 5ce221cc..78fbd18b 100644 --- a/WebLab/SeguimientoResultados.aspx.cs +++ b/WebLab/SeguimientoResultados.aspx.cs @@ -269,32 +269,32 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(oItem); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); + + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); GridView dg = new GridView(); dg.EnableViewState = false; dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - + dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound1); dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Solo_Resultados_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); + Utility.ExportGridViewToExcel(dg, "CodVid_Solo_Resultados_" + DateTime.Now.ToShortDateString()); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Solo_Resultados_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/SeguimientoResultadosSemanal.aspx.cs b/WebLab/SeguimientoResultadosSemanal.aspx.cs index ad21d813..08292ee8 100644 --- a/WebLab/SeguimientoResultadosSemanal.aspx.cs +++ b/WebLab/SeguimientoResultadosSemanal.aspx.cs @@ -195,35 +195,34 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); GridView dg = new GridView(); dg.EnableViewState = false; dg.DataSource = tabla; - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound1); - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Resumen_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); + Utility.ExportGridViewToExcel(dg, "CodVid_Resumen_" + DateTime.Now.ToShortDateString() ); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=CodVid_Resumen_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } - catch + catch(Exception e) { lblError.Text = "Ha superado el límite para exportar datos. Comuniquese con el administrador."; From f27a8bc91c24243517a567dd492d3181701d6507 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Fri, 28 Nov 2025 10:55:52 -0300 Subject: [PATCH 07/10] FIX; exportar datatable sin color, con bordes y alineado --- Business/Utility.cs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Business/Utility.cs b/Business/Utility.cs index 1d04fcd0..59a8ef6a 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -889,10 +889,8 @@ public static void ExportDataTableToXlsx(DataTable dataTable, string filename) HttpResponse response = HttpContext.Current.Response; - // Define el color de fondo por defecto si no se proporciona - // --azul-neuquen: #2b3e4c; - Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen - + // Color finalBackColor = ColorTranslator.FromHtml("#2b3e4c"); //azul-neuquen + // Color fontColor = Color.White using (ExcelPackage package = new ExcelPackage()) { // Crear una nueva hoja de trabajo @@ -966,12 +964,15 @@ out numero // Rango del encabezado: Desde A1 hasta el final de la primera fila using (var range = worksheet.Cells[1, 1, 1, colCount]) { - ApplyHeaderStyle(range, finalBackColor); + ExcelEstilo(range); } // Autoajusta las columnas worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); + //Todas las celdas + var range2 = worksheet.Cells[1, 1, rowCount+1, colCount]; //row+1 asi cuenta la fila del encabezado. + ExcelBordes(range2); // --- CONFIGURAR RESPUESTA HTTP --- response.Clear(); response.Buffer = true; @@ -990,12 +991,24 @@ out numero } - private static void ApplyHeaderStyle(ExcelRange range, Color backColor) + private static void ExcelEstilo(ExcelRange range, Color? backColor = null, Color? fontColor = null) { + Color finalBackColor = backColor ?? Color.Transparent; + Color finalFontColor = fontColor ?? Color.Black; + range.Style.Font.Bold = true; range.Style.Fill.PatternType = ExcelFillStyle.Solid; - range.Style.Fill.BackgroundColor.SetColor(backColor); - range.Style.Font.Color.SetColor(Color.White); // Color de fuente blanco (opcional) + range.Style.Fill.BackgroundColor.SetColor(finalBackColor); + range.Style.Font.Color.SetColor(finalFontColor); + range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; + } + + private static void ExcelBordes(ExcelRange rango) + { + rango.Style.Border.Top.Style = ExcelBorderStyle.Thin; + rango.Style.Border.Bottom.Style = ExcelBorderStyle.Thin; + rango.Style.Border.Left.Style = ExcelBorderStyle.Thin; + rango.Style.Border.Right.Style = ExcelBorderStyle.Thin; } public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) @@ -1018,7 +1031,7 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) if (encabezadoColor == fontColor) { - encabezadoColor = Color.White; + encabezadoColor = Color.Transparent; fontColor = Color.Black; } foreach (DataControlField column in grid.Columns) From 9db9d04bce7d5a6a43006dd5468a1baaa1c37c0d Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Fri, 28 Nov 2025 11:03:03 -0300 Subject: [PATCH 08/10] feature: cambios de exportacion de excel en aspx --- WebLab/Estadisticas/ReporteForense.aspx.cs | 51 +++++++++--------- .../Estadisticas/ReporteMicrobiologia.aspx.cs | 14 +++-- WebLab/SeguimientoResultadosSemanal.aspx.cs | 17 +++--- WebLab/SeguimientoSecuenciacion.aspx.cs | 54 ++++++++++--------- WebLab/SeguimientoTestAntigenos.aspx.cs | 54 ++++++++++--------- WebLab/SeleccionSecuenciacion.aspx.cs | 54 ++++++++++--------- WebLab/Usuarios/UsuarioList.aspx.cs | 45 ++++++++-------- 7 files changed, 148 insertions(+), 141 deletions(-) diff --git a/WebLab/Estadisticas/ReporteForense.aspx.cs b/WebLab/Estadisticas/ReporteForense.aspx.cs index 9fa497ed..78f01631 100644 --- a/WebLab/Estadisticas/ReporteForense.aspx.cs +++ b/WebLab/Estadisticas/ReporteForense.aspx.cs @@ -328,31 +328,32 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcelTipoMuestra() { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - - Page page = new Page(); - HtmlForm form = new HtmlForm(); - gvCasos.EnableViewState = false; - - // Deshabilitar la validación de eventos, sólo asp.net 2 - page.EnableEventValidation = false; - - // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. - page.DesignerInitialize(); - page.Controls.Add(form); - form.Controls.Add(gvCasos); - page.RenderControl(htw); - - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=NoPaciente_TipoMuestra.xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportGridViewToExcel(gvCasos, "NoPaciente_TipoMuestra"); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + + //Page page = new Page(); + //HtmlForm form = new HtmlForm(); + //gvCasos.EnableViewState = false; + + //// Deshabilitar la validación de eventos, sólo asp.net 2 + //page.EnableEventValidation = false; + + //// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. + //page.DesignerInitialize(); + //page.Controls.Add(form); + //form.Controls.Add(gvCasos); + //page.RenderControl(htw); + + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=NoPaciente_TipoMuestra.xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } diff --git a/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs b/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs index 5951fff4..51eb36af 100644 --- a/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs +++ b/WebLab/Estadisticas/ReporteMicrobiologia.aspx.cs @@ -1455,23 +1455,21 @@ private void ExportarExcelMecanismo() protected void imgPacientesMecanismo_Click(object sender, ImageClickEventArgs e) { - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = GetDataPacientes("Mecanismo"); - dg.DataBind(); - Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); - Utility.ExportGridViewToExcel(dg, ddlAnalisis.SelectedItem.Text + "_Mecanismo"); + Utility.ExportDataTableToXlsx(GetDataPacientes("Mecanismo"), ddlAnalisis.SelectedItem.Text + "_Mecanismo"); // StringBuilder sb = new StringBuilder(); // StringWriter sw = new StringWriter(sb); // HtmlTextWriter htw = new HtmlTextWriter(sw); // Page page = new Page(); // HtmlForm form = new HtmlForm(); - + // // Deshabilitar la validación de eventos, sólo asp.net 2 // page.EnableEventValidation = false; - + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = GetDataPacientes("Mecanismo"); + //dg.DataBind(); // // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD. // page.DesignerInitialize(); // page.Controls.Add(form); diff --git a/WebLab/SeguimientoResultadosSemanal.aspx.cs b/WebLab/SeguimientoResultadosSemanal.aspx.cs index 08292ee8..cdc93303 100644 --- a/WebLab/SeguimientoResultadosSemanal.aspx.cs +++ b/WebLab/SeguimientoResultadosSemanal.aspx.cs @@ -195,18 +195,19 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(); if (tabla.Rows.Count > 0) { + Utility.ExportDataTableToXlsx(tabla, "CodVid_Resumen_" + DateTime.Now.ToShortDateString()); //StringBuilder sb = new StringBuilder(); //StringWriter sw = new StringWriter(sb); //HtmlTextWriter htw = new HtmlTextWriter(sw); //Page pagina = new Page(); //HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound1); - dg.DataBind(); - Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); - Utility.ExportGridViewToExcel(dg, "CodVid_Resumen_" + DateTime.Now.ToShortDateString() ); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound1); + //dg.DataBind(); + //Utility.GenerarColumnasGrid(dg, dg.DataSource as DataTable); + //pagina.EnableEventValidation = false; //pagina.DesignerInitialize(); //pagina.Controls.Add(form); @@ -222,7 +223,7 @@ private void ExportarExcel() //Response.End(); } } - catch(Exception e) + catch { lblError.Text = "Ha superado el límite para exportar datos. Comuniquese con el administrador."; diff --git a/WebLab/SeguimientoSecuenciacion.aspx.cs b/WebLab/SeguimientoSecuenciacion.aspx.cs index 666cfaf3..b1ce21b7 100644 --- a/WebLab/SeguimientoSecuenciacion.aspx.cs +++ b/WebLab/SeguimientoSecuenciacion.aspx.cs @@ -229,32 +229,34 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(oItem); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=VigilanciaGenomica_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "VigilanciaGenomica_" + DateTime.Now.ToShortDateString()); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound1); + + + //dg.DataBind(); + + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=VigilanciaGenomica_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/SeguimientoTestAntigenos.aspx.cs b/WebLab/SeguimientoTestAntigenos.aspx.cs index 6faab47b..01bab64e 100644 --- a/WebLab/SeguimientoTestAntigenos.aspx.cs +++ b/WebLab/SeguimientoTestAntigenos.aspx.cs @@ -196,32 +196,34 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=testAntigeno_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "testAntigeno_" + DateTime.Now.ToShortDateString()); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); + + + //dg.DataBind(); + + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=testAntigeno_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } catch diff --git a/WebLab/SeleccionSecuenciacion.aspx.cs b/WebLab/SeleccionSecuenciacion.aspx.cs index 63cd8fbe..28a6e3e7 100644 --- a/WebLab/SeleccionSecuenciacion.aspx.cs +++ b/WebLab/SeleccionSecuenciacion.aspx.cs @@ -160,32 +160,34 @@ private void ExportarExcel() DataTable tabla = MostrarDatos(oItem); if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - - dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); - - - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=SeleccionSecuenciacion_" + DateTime.Now.ToShortDateString() + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, "SeleccionSecuenciacion_" + DateTime.Now.ToShortDateString()); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + + //dg.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound); + + + //dg.DataBind(); + + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=SeleccionSecuenciacion_" + DateTime.Now.ToShortDateString() + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } diff --git a/WebLab/Usuarios/UsuarioList.aspx.cs b/WebLab/Usuarios/UsuarioList.aspx.cs index 039e1a1c..e3a181b5 100644 --- a/WebLab/Usuarios/UsuarioList.aspx.cs +++ b/WebLab/Usuarios/UsuarioList.aspx.cs @@ -276,28 +276,29 @@ private void dataTableAExcel(DataTable tabla, string nombreArchivo) { if (tabla.Rows.Count > 0) { - StringBuilder sb = new StringBuilder(); - StringWriter sw = new StringWriter(sb); - HtmlTextWriter htw = new HtmlTextWriter(sw); - Page pagina = new Page(); - HtmlForm form = new HtmlForm(); - GridView dg = new GridView(); - dg.EnableViewState = false; - dg.DataSource = tabla; - dg.DataBind(); - pagina.EnableEventValidation = false; - pagina.DesignerInitialize(); - pagina.Controls.Add(form); - form.Controls.Add(dg); - pagina.RenderControl(htw); - Response.Clear(); - Response.Buffer = true; - Response.ContentType = "application/vnd.ms-excel"; - Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); - Response.Charset = "UTF-8"; - Response.ContentEncoding = Encoding.Default; - Response.Write(sb.ToString()); - Response.End(); + Utility.ExportDataTableToXlsx(tabla, nombreArchivo); + //StringBuilder sb = new StringBuilder(); + //StringWriter sw = new StringWriter(sb); + //HtmlTextWriter htw = new HtmlTextWriter(sw); + //Page pagina = new Page(); + //HtmlForm form = new HtmlForm(); + //GridView dg = new GridView(); + //dg.EnableViewState = false; + //dg.DataSource = tabla; + //dg.DataBind(); + //pagina.EnableEventValidation = false; + //pagina.DesignerInitialize(); + //pagina.Controls.Add(form); + //form.Controls.Add(dg); + //pagina.RenderControl(htw); + //Response.Clear(); + //Response.Buffer = true; + //Response.ContentType = "application/vnd.ms-excel"; + //Response.AddHeader("Content-Disposition", "attachment;filename=" + nombreArchivo + ".xls"); + //Response.Charset = "UTF-8"; + //Response.ContentEncoding = Encoding.Default; + //Response.Write(sb.ToString()); + //Response.End(); } } } From c460cb93aa11f56717342a3f873be454c3785703 Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Fri, 28 Nov 2025 15:18:00 -0300 Subject: [PATCH 09/10] fix: para poner el footer del grid en el excel --- Business/Utility.cs | 126 +++++++++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/Business/Utility.cs b/Business/Utility.cs index 59a8ef6a..2b7d780e 100644 --- a/Business/Utility.cs +++ b/Business/Utility.cs @@ -996,6 +996,12 @@ private static void ExcelEstilo(ExcelRange range, Color? backColor = null, Color Color finalBackColor = backColor ?? Color.Transparent; Color finalFontColor = fontColor ?? Color.Black; + if (backColor == fontColor) + { + finalBackColor = Color.Transparent; + finalFontColor = Color.Black; + } + range.Style.Border.BorderAround(ExcelBorderStyle.Thin); range.Style.Font.Bold = true; range.Style.Fill.PatternType = ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(finalBackColor); @@ -1050,7 +1056,7 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) fila++; // ================================ - // 2) Escribir filas + colores del GridView + // 2) Escribir filas // ================================ foreach (GridViewRow row in grid.Rows) { @@ -1058,55 +1064,39 @@ public static void ExportGridViewToExcel(GridView grid, string nombreArchivo) foreach (TableCell cell in row.Cells) { - // (2) Decodificar texto HTML - var texto = HttpUtility.HtmlDecode(cell.Text); - - // (1) Detectar si es número - double numero; - bool esNumero = double.TryParse( - texto, - System.Globalization.NumberStyles.Any, - System.Globalization.CultureInfo.GetCultureInfo("es-ES"), // Usar una cultura que use la coma como separador decimal - out numero - ); - - if (esNumero) - { - ws.Cells[fila, col].Value = numero; - } - else - { - ws.Cells[fila, col].Value = texto; - } - - // Aplicar colores si existen - - - if (cell.BackColor != Color.Empty) - { - ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; - ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(cell.BackColor); - } - - if (cell.ForeColor != Color.Empty) - { - ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); - } - - - - ws.Cells[fila, col].Style.Border.BorderAround(ExcelBorderStyle.Thin); - ws.Cells[fila, col].Style.Font.Size = 9; - //ws.Cells[fila, col].Style.WrapText = true; //Ajusta texto largo en la celda + ExcelCompletarFilas(ws, cell, fila, col); col++; } fila++; } - + //Todas las celdas + var range2 = ws.Cells[1, 1, grid.Rows.Count + 1, grid.Columns.Count]; + ExcelBordes(range2); // Autoajustar columnas ws.Cells[1, 1, fila - 1, grid.Columns.Count].AutoFitColumns(); + // ================================ + // 2.2) Escribir filas del footer + // ================================ + + GridViewRow filaFooter = grid.FooterRow; + col = 1; + + if (tieneValores(filaFooter.Cells)) + { + foreach (TableCell cell in filaFooter.Cells) + { + ExcelCompletarFilas(ws, cell, fila, col, encabezadoColor, fontColor); + ws.Cells[fila, col].Style.Font.Bold = true; + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(encabezadoColor); + ws.Cells[fila, col].Style.Font.Color.SetColor(fontColor); + col++; + } + ExcelBordes(ws.Cells[grid.Rows.Count + 2,1, grid.Rows.Count + 2,col-1 ]); + } + // ================================ // 3) Descargar archivo // ================================ @@ -1121,6 +1111,58 @@ out numero } } + } + private static bool tieneValores(TableCellCollection footer) + { + + foreach (TableCell cell in footer) + { + var texto = HttpUtility.HtmlDecode(cell.Text); + if (!string.IsNullOrEmpty(texto.Trim())) + return true; + } + + return false; + } + + private static void ExcelCompletarFilas(ExcelWorksheet ws, TableCell cell, int fila, int col, Color? encabezadoColor = null, Color? fontColor = null) + { + // (2) Decodificar texto HTML + var texto = HttpUtility.HtmlDecode(cell.Text); + // (1) Detectar si es número + double numero; + bool esNumero = double.TryParse( + texto, + System.Globalization.NumberStyles.Any, + System.Globalization.CultureInfo.GetCultureInfo("es-ES"), // Usar una cultura que use la coma como separador decimal + out numero + ); + + if (esNumero) + { + ws.Cells[fila, col].Value = numero; + } + else + { + ws.Cells[fila, col].Value = texto; + } + + // Aplicar colores si existen + + + if (cell.BackColor != Color.Empty) + { + ws.Cells[fila, col].Style.Fill.PatternType = ExcelFillStyle.Solid; + ws.Cells[fila, col].Style.Fill.BackgroundColor.SetColor(cell.BackColor); + } + + if (cell.ForeColor != Color.Empty) + { + ws.Cells[fila, col].Style.Font.Color.SetColor(cell.ForeColor); + } + + ws.Cells[fila, col].Style.Font.Size = 9; + } public static void GenerarColumnasGrid(GridView grid, DataTable dt) From 2fe3dbbe0c26a4950358b73bdf8248d8a028c6df Mon Sep 17 00:00:00 2001 From: Vanesa Rimada <80859025+vrimada@users.noreply.github.com> Date: Fri, 28 Nov 2025 15:20:56 -0300 Subject: [PATCH 10/10] feature; cambio de metodo para exportar a excel --- WebLab/Estadisticas/Reporte.aspx.cs | 21 ++++++++++++++++--- .../Estadisticas/ReporteIncidencias.aspx.cs | 5 ++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/WebLab/Estadisticas/Reporte.aspx.cs b/WebLab/Estadisticas/Reporte.aspx.cs index 87b25b04..eb56a26f 100644 --- a/WebLab/Estadisticas/Reporte.aspx.cs +++ b/WebLab/Estadisticas/Reporte.aspx.cs @@ -467,7 +467,7 @@ private DataTable GetDatosEstadistica(string s_tipo) case "8": cmd.CommandText = "LAB_EstadisticaPorSector"; break; case "9": cmd.CommandText = "LAB_EstadisticaRankingDia"; break; case "10": cmd.CommandText = "LAB_EstadisticaPorHorario"; break; - + // menu falta case 11!!!!! } @@ -776,8 +776,23 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcel() { - Utility.GenerarColumnasGrid(gvEstadistica, gvEstadistica.DataSource as DataTable); - Utility.ExportGridViewToExcel(gvEstadistica, "estadistica"); + DataTable tabla = new DataTable(); + + if (Session["informe"].ToString() == "General") + tabla = GetDatosEstadistica("GV"); + else + { + if (Session["informe"].ToString() == "PorResultado") + tabla = GetDatosPorResultado(); + } + + GridView dg = new GridView(); + dg.EnableViewState = false; + dg.DataSource = tabla; + dg.RowDataBound += new GridViewRowEventHandler(gvEstadistica_RowDataBound); + dg.DataBind(); + Utility.GenerarColumnasGrid(dg, tabla); + Utility.ExportGridViewToExcel(dg, "estadistica"); //StringBuilder sb = new StringBuilder(); //StringWriter sw = new StringWriter(sb); diff --git a/WebLab/Estadisticas/ReporteIncidencias.aspx.cs b/WebLab/Estadisticas/ReporteIncidencias.aspx.cs index 1392e87e..288f8683 100644 --- a/WebLab/Estadisticas/ReporteIncidencias.aspx.cs +++ b/WebLab/Estadisticas/ReporteIncidencias.aspx.cs @@ -197,7 +197,7 @@ protected void imgExcel_Click(object sender, ImageClickEventArgs e) private void ExportarExcel(string nombreArchivo) { - Utility.ExportGridViewToExcel(GridView1, nombreArchivo); + Utility.ExportGridViewToExcel(GridView1, nombreArchivo); //StringBuilder sb = new StringBuilder(); //StringWriter sw = new StringWriter(sb); @@ -233,6 +233,9 @@ protected void imgExcel0_Click(object sender, ImageClickEventArgs e) private void ExportarExcel2(string p) { + // gvProtocolos.EnableViewState = false; + //gvProtocolos.RowDataBound += new GridViewRowEventHandler(GridView2_RowDataBound); //Para que ponga el pie de "Totales" + //gvProtocolos.DataBind(); Utility.ExportGridViewToExcel(gvProtocolos, p); //StringBuilder sb = new StringBuilder(); //StringWriter sw = new StringWriter(sb);