protected void rdGridComportamientoPago_ItemCommand1(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.ExportToExcelCommandName) { DataTable dtcompPago = null; DataTable dt = null; DBConn oConn = new DBConn(); if (oConn.Open()) { cComportamientoPago oComportamientoPago = new cComportamientoPago(ref oConn); oComportamientoPago.CodDeudor = hddCodDeudor.Value; oComportamientoPago.CodNkey = oIsUsuario.CodNkey; oComportamientoPago.NkeyUsuario = oIsUsuario.NKeyUsuario; oComportamientoPago.TipoUsuario = oIsUsuario.TipoUsuario; oComportamientoPago.CodAnalista = hddCodAnalista.Value; oComportamientoPago.Estado = rdBtnTypeQuery.SelectedValue; dtcompPago = oComportamientoPago.Get(); } oConn.Close(); dt = getDatatble(dtcompPago); XLWorkbook wb = new XLWorkbook(); wb.Worksheets.Add(dt, "comportamientopago"); Response.Clear(); Response.Buffer = true; Response.Charset = ""; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment;filename=comportamientopago_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"); using (MemoryStream MyMemoryStream = new MemoryStream()) { wb.SaveAs(MyMemoryStream); MyMemoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } }
protected void getGrid() { DataTable dtcompPago = null; DataTable dt; DBConn oConn = new DBConn(); if (oConn.Open()) { cComportamientoPago oComportamientoPago = new cComportamientoPago(ref oConn); oComportamientoPago.CodDeudor = hddCodDeudor.Value; oComportamientoPago.CodNkey = ((!string.IsNullOrEmpty(cmbCliente.SelectedValue) ? cmbCliente.SelectedValue : hdd_arrNkeyCliente.Value)); oComportamientoPago.NcodHolding = cmbHolding.SelectedValue; oComportamientoPago.NkeyUsuario = oIsUsuario.NKeyUsuario; oComportamientoPago.TipoUsuario = oIsUsuario.TipoUsuario; oComportamientoPago.CodAnalista = hddCodAnalista.Value; oComportamientoPago.Estado = rdBtnTypeQuery.SelectedValue; dtcompPago = oComportamientoPago.Get(); } oConn.Close(); GridBoundColumn oGridBoundColumn; dt = getDatatble(dtcompPago); if (dtcompPago != null) { if (dtcompPago.Rows.Count > 0) { rdGridComportamientoPago.MasterTableView.Columns.Clear(); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = "mesfila"; oGridBoundColumn.HeaderText = "mesfila"; oGridBoundColumn.UniqueName = "mesfila"; rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano"].ToString(); oGridBoundColumn.UniqueName = "Actual"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano1"].ToString(); oGridBoundColumn.UniqueName = "Mes-1"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano1"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano2"].ToString(); oGridBoundColumn.UniqueName = "Mes-2"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano2"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano3"].ToString(); oGridBoundColumn.UniqueName = "Mes-3"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano3"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano4"].ToString(); oGridBoundColumn.UniqueName = "Mes-4"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano4"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano5"].ToString(); oGridBoundColumn.UniqueName = "Mes-5"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano5"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano6"].ToString(); oGridBoundColumn.UniqueName = "Mes-6"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano6"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano7"].ToString(); oGridBoundColumn.UniqueName = "Mes-7"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano7"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano8"].ToString(); oGridBoundColumn.UniqueName = "Mes-8"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano8"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); oGridBoundColumn = new GridBoundColumn(); oGridBoundColumn.DataField = dtcompPago.Rows[0]["mesano9"].ToString(); oGridBoundColumn.UniqueName = "Mes-9"; oGridBoundColumn.DataFormatString = "{0:n}"; oGridBoundColumn.HeaderText = dtcompPago.Rows[0]["mesano9"].ToString(); rdGridComportamientoPago.MasterTableView.Columns.Add(oGridBoundColumn); } } dtcompPago = null; rdGridComportamientoPago.DataSource = dt; }