Buenos Dias would like you to help me I'm doing in c # export excel the truth if it works everything I would like is just to press on my botton I will generate my excel but in the sheets the fields that are in my conbobox are added. how is it in the image:
since now when I press one each one if it generates me but I want that only one button generates everything in different sheets
protected void ExportExcel(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
string query = "COMISION";
//string query = "exec COMISION_DIC16 @TC, @Fecha_FDM, @OPC";
//string query = "select top 5 NPtmo,Oficina,SecCod,SecNom,Otorgado from TCalificacion ";
//query += "SELECT TOP 10 idorigencredito, segmentotasa, segmentocartera FROM credito..credito;";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandTimeout = 90000000;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("TC", SqlDbType.VarChar, 50).Value = txtTC.Text;
cmd.Parameters.Add("Fecha_FDM", SqlDbType.VarChar, 50).Value = txtFecha_FDM.Text;
cmd.Parameters.Add("OPC", SqlDbType.VarChar, 50).Value = OPC.SelectedItem.Value;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
//Set Name of DataTables.
ds.Tables[0].TableName = "REPORTES";
//ds.Tables[1].TableName = "DetalleDesembolso";
using (XLWorkbook wb = new XLWorkbook())
{
foreach (DataTable dt in ds.Tables)
{
//Add DataTable as Worksheet.
wb.Worksheets.Add(dt);
}
//Export the Excel file.
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=Reporte_Comision.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
}
}
}
}