private void btn_excel_Click(object sender, EventArgs e) { Random r = new Random(); String fileName = @"N:\contabilidad_ef\EstadoFinancieroNaturaleza" + "-" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + r.Next(1, 30) + ".xls"; String fileName2 = @"N:\contabilidad_ef\EstadoFinancieroFuncion" + "-" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + r.Next(1, 30) + ".xls"; String fileName3 = @"N:\contabilidad_ef\EstadoFlujoEfectivo" + "-" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + r.Next(1, 30) + ".xls"; String fileName4 = @"N:\contabilidad_ef\BalanceComprobacion" + "-" + DateTime.Now.ToString("dd-MM-yyyy") + "-" + r.Next(1, 30) + ".xls"; if (cmb_estado.SelectedValue.ToString() == "01") { objListEGPN = objAsientoDao.getEstadoGPNaturaleza(cmb_anio.SelectedValue.ToString(), cmb_Mes.SelectedValue.ToString()); //objListEGPN.Sort(objn.Desc); btn_excel.Enabled = false; Reporte.GananciasPerdidasNaturaleza cr = new Reporte.GananciasPerdidasNaturaleza(); cr.SetDataSource(objListEGPN); 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; } else if (cmb_estado.SelectedValue.ToString() == "02") { objListEGPF = objAsientoDao.getEstadoGPFuncion(cmb_anio.SelectedValue.ToString(), cmb_Mes.SelectedValue.ToString()); btn_excel.Enabled = false; Reporte.GananciasPerdidasFuncion cr = new Reporte.GananciasPerdidasFuncion(); cr.SetDataSource(objListEGPF); 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 = fileName2; exportOpts.DestinationOptions = diskOpts; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); cr.Export(); btn_excel.Enabled = true; } else if (cmb_estado.SelectedValue.ToString() == "03") { objListFE = objAsientoDao.getEstadoFlujoEfectivo(cmb_anio.SelectedValue.ToString(), cmb_Mes.SelectedValue.ToString()); btn_excel.Enabled = false; Reporte.EstadoFlujoEfectivo cr = new Reporte.EstadoFlujoEfectivo(); cr.SetDataSource(objListFE); 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 = fileName3; exportOpts.DestinationOptions = diskOpts; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); cr.Export(); btn_excel.Enabled = true; } else if (cmb_estado.SelectedValue.ToString() == "04") { //objListFE = objAsientoDao.getEstadoFlujoEfectivo(cmb_anio.SelectedValue.ToString(), cmb_Mes.SelectedValue.ToString()); btn_excel.Enabled = false; Reporte.BalanceComprobacion cr = new Reporte.BalanceComprobacion(); //cr.SetDataSource(objListFE); 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 = fileName4; exportOpts.DestinationOptions = diskOpts; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); cr.Export(); btn_excel.Enabled = true; } }