protected void exportarXLS() { BL_LOGISTICA obj = new BL_LOGISTICA(); DataTable dtResultadoeExcel = new DataTable(); string empresa = RdoEmpresa.SelectedValue; dtResultadoeExcel = obj.ListarProcesao_ReporteGlobal(empresa); //gvwAsignacion.Visible = false; //gvwAsignacion.DataSource = dtResultadoeExcel; //gvwAsignacion.DataBind(); string cleanMessage = ""; if (dtResultadoeExcel.Rows.Count > 0) { // cleanMessage = "Proceso Satisfactorio"; //GridViewExportUtil.Export("REPORTE_GLOBAL_" + empresa + ".xls", gvwAsignacion); //return; } else { cleanMessage = "Se encontraron errores al exportar la carga de Reporte"; ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true); } }
protected void exportarXLS_Plantilla() { BL_LOGISTICA obj = new BL_LOGISTICA(); DataTable dtbReporte = new DataTable(); string empresa = RdoEmpresa.SelectedValue; dtbReporte = obj.ListarProcesao_ReporteGlobal(empresa); int Col; int Fil; try { Excel.Application excelApp = new Excel.Application(); string workbookPath = Server.MapPath("~/Plantilla/ReporteGlobal.xltx"); Excel.Workbook excelWorkbook = null; try { excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); } catch { excelWorkbook = excelApp.Workbooks.Add(); } Excel.Sheets excelSheets = excelWorkbook.Worksheets; string currentSheet = "Reporte General"; Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet); // The following gets cell A1 for editing //Excel.Range excelCell = (Excel.Range)excelWorksheet; if (dtbReporte.Rows.Count > 0) { Col = 1; Fil = 2; foreach (DataRow objRow in dtbReporte.Rows) { ((Excel.Range)excelWorksheet.Cells[Fil, Col]).Value = objRow[0]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 1]).Value = objRow[1]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 2]).Value = objRow[2]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 3]).Value = objRow[3]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 4]).Value = objRow[4]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 5]).Value = objRow[5]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 6]).Value = objRow[6]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 7]).Value = objRow[7]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 8]).Value = objRow[8]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 9]).Value = objRow[9]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 10]).Value = objRow[10]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 11]).Value = objRow[11]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 12]).Value = objRow[12]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 13]).Value = objRow[13]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 14]).Value = objRow[14]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 15]).Value = objRow[15]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 16]).Value = objRow[16]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 17]).Value = objRow[17]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 18]).Value = objRow[18]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 19]).Value = objRow[19]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 20]).Value = objRow[20]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 21]).Value = objRow[21]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 22]).Value = objRow[22]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 23]).Value = objRow[23]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 24]).Value = objRow[24]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 25]).Value = objRow[25]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 26]).Value = objRow[26]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 27]).Value = objRow[27]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 28]).Value = objRow[28]; ((Excel.Range)excelWorksheet.Cells[Fil, Col + 29]).Value = objRow[29]; //.Cells[Fil, Col + 30] = objRow.Item[30) //.Cells[Fil, Col + 31] = objRow.Item[31) Fil = Fil + 1; } excelApp.Visible = true; return; } else { UC_MessageBox.Show(Page, this.GetType(), "Error al realizar calculo en Reporte Global."); return; } //exportarXLS(dtbReporte); } catch (Exception ex) { UC_MessageBox.Show(Page, this.GetType(), ex.Message); return; } finally { } }