private void BT_exportar_Click(object sender, EventArgs e) { DateTime F_ini, F_fin; string inicio = "", fin = ""; F_ini = DT_inicio.Value; F_fin = DT_fin.Value; inicio = F_ini.ToLongDateString(); fin = F_fin.ToLongDateString(); Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); int indiceColumna = 0; foreach (DataGridViewColumn col in DG_comisiones.Columns) { indiceColumna++; excel.Cells[5, indiceColumna] = col.Name; } int indiceFila = 4; foreach (DataGridViewRow row in DG_comisiones.Rows) { indiceFila++; indiceColumna = 0; foreach (DataGridViewColumn col in DG_comisiones.Columns) { indiceColumna++; excel.Cells[indiceFila + 1, indiceColumna] = row.Cells[col.Name].Value; } } excel.Cells.Range["A4:J4"].Merge(); excel.Cells.Range["A4"].Value = "COMISIONES DE LA SEMANA DEL " + inicio.ToUpper() + " AL " + fin.ToUpper(); excel.Cells.Range["K17"].Value = "TOTAL INCENTIVO ="; excel.Cells.Range["L17"].Value = getIncentivo(); excel.Cells.Range["K18"].Value = "TOTAL COMISION ="; excel.Cells.Range["L18"].Value = getTotal(); excel.Cells.Range["B6:I16"].NumberFormat = "$#,##0.00"; excel.Cells.Range["I6:I16"].NumberFormat = "$#,##0.00"; excel.Cells.Range["J6:J16"].NumberFormat = "$#,##0.00"; excel.Cells.Range["K6:K16"].NumberFormat = "$#,##0.00"; excel.Cells.Range["L6:L16"].NumberFormat = "$#,##0.00"; excel.Visible = true; }
public void ExportarExcel() { DateTime F_ini, F_fin; string inicio = "", fin = ""; F_ini = DT_inicio.Value; F_fin = DT_fin.Value; inicio = F_ini.ToLongDateString(); fin = F_fin.ToLongDateString(); Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); int indiceColumna = 0; foreach (DataGridViewColumn col in DG_comisiones.Columns) { indiceColumna++; excel.Cells[5, indiceColumna] = col.Name; } int indiceFila = 4; foreach (DataGridViewRow row in DG_comisiones.Rows) { indiceFila++; indiceColumna = 0; foreach (DataGridViewColumn col in DG_comisiones.Columns) { indiceColumna++; excel.Cells[indiceFila + 1, indiceColumna] = row.Cells[col.Name].Value; } } excel.Cells.Range["A4:J4"].Merge(); excel.Cells.Range["A4"].Value = "COMISIONES DEL " + inicio.ToUpper() + " AL " + fin.ToUpper(); excel.Cells.Range["A5:Q25"].Font.Size = 9; excel.Cells.Range["D6:Q25"].NumberFormat = "$#,##0.00"; excel.Cells.Range["A30:B30"].Merge(); excel.Cells.Range["A30"].NumberFormat = "$#,##0.00"; excel.Cells.Range["A30"].Value = "Total a pagar " + TB_total.Text; excel.Visible = true; }