private void btn_excel_Click(object sender, EventArgs e) { Random r = new Random(); String fileName = @"N:\Balance\EstadoFinancieroNaturaleza" + "-" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + r.Next(1, 30) + ".xls"; if (cmb_anio.SelectedValue.ToString() == "2019" && cmb_Mes.SelectedValue.ToString() == "1") { Anio2 = "2018"; Mes2 = "12"; } else if (cmb_Mes.SelectedValue.ToString() == "2") { Anio2 = "2019"; Mes2 = "1"; } else if (cmb_Mes.SelectedValue.ToString() == "3") { Anio2 = "2019"; Mes2 = "2"; } else if (cmb_Mes.SelectedValue.ToString() == "4") { Anio2 = "2019"; Mes2 = "3"; } else if (cmb_Mes.SelectedValue.ToString() == "5") { Anio2 = "2019"; Mes2 = "4"; } else if (cmb_Mes.SelectedValue.ToString() == "6") { Anio2 = "2019"; Mes2 = "5"; } else if (cmb_Mes.SelectedValue.ToString() == "7") { Anio2 = "2019"; Mes2 = "6"; } else if (cmb_Mes.SelectedValue.ToString() == "8") { Anio2 = "2019"; Mes2 = "7"; } else if (cmb_Mes.SelectedValue.ToString() == "9") { Anio2 = "2019"; Mes2 = "8"; } else if (cmb_Mes.SelectedValue.ToString() == "10") { Anio2 = "2019"; Mes2 = "9"; } else if (cmb_Mes.SelectedValue.ToString() == "11") { Anio2 = "2019"; Mes2 = "10"; } objListBalance = objAsientoDao.getBalanceGeneral(cmb_anio.SelectedValue.ToString(), cmb_Mes.SelectedValue.ToString(), Anio2.ToString(), Mes2.ToString()); btn_excel.Enabled = false; Reporte.BalanceGeneral cr = new Reporte.BalanceGeneral(); cr.SetDataSource(objListBalance); ExportOptions exportOpts = new ExportOptions(); ExcelFormatOptions excelFormatOpts = new ExcelFormatOptions(); DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions(); exportOpts = cr.ExportOptions; // Set the excel format options. excelFormatOpts.ExcelUseConstantColumnWidth = true; excelFormatOpts.ExcelTabHasColumnHeadings = true; excelFormatOpts.ShowGridLines = true; excelFormatOpts.ExportPageBreaksForEachPage = true; //excelFormatOpts.UsePageRange = true; exportOpts.ExportFormatType = ExportFormatType.Excel; exportOpts.FormatOptions = excelFormatOpts; // Set the disk file options and export. exportOpts.ExportDestinationType = ExportDestinationType.DiskFile; diskOpts.DiskFileName = fileName; exportOpts.DestinationOptions = diskOpts; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); cr.Export(); btn_excel.Enabled = true; }