public static void armarExcelListaCompras(DataGridView dgv_tabla) { ControladorFuncVariadas control = new ControladorFuncVariadas(); Cursor.Current = Cursors.WaitCursor; Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Interactive = false; try { Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = (Worksheet)Excel.ActiveSheet; Excel.WindowState = XlWindowState.xlMaximized; Microsoft.Office.Interop.Excel.Range cabecera = null; ws.Cells[1, 1] = "Lista Compras"; ws.Range[ws.Cells[1, 1], ws.Cells[3, 11]].Merge(); cabecera = ws.get_Range("a1", "k3"); ws.Cells[1, 1].Font.Bold = true; ws.Cells[1, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[1, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[1, 1].Font.Size = 20; cabecera.BorderAround2(); cabecera.Interior.Color = Color.White; ws.Cells[4, 1] = "Proveedor"; ws.Cells[4, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 1].Font.Bold = true; Microsoft.Office.Interop.Excel.Range proveedor = ws.get_Range("a4", "a4"); proveedor.BorderAround2(); proveedor.Interior.Color = Color.White; ws.Cells[4, 2] = "Motivo"; ws.Cells[4, 2].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 2].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 2].Font.Bold = true; Microsoft.Office.Interop.Excel.Range motivo = ws.get_Range("b4", "b4"); motivo.BorderAround2(); motivo.Interior.Color = Color.White; ws.Cells[4, 3] = "Vencimiento"; ws.Cells[4, 3].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 3].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 3].Font.Bold = true; Microsoft.Office.Interop.Excel.Range vencimiento = ws.get_Range("c4", "c4"); vencimiento.BorderAround2(); vencimiento.Interior.Color = Color.White; ws.Cells[4, 4] = "Monto"; ws.Cells[4, 4].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 4].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 4].Font.Bold = true; Microsoft.Office.Interop.Excel.Range monto = ws.get_Range("d4", "d4"); monto.BorderAround2(); monto.Interior.Color = Color.White; ws.Cells[4, 5] = "Fecha de Ingreso"; ws.Cells[4, 5].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 5].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 5].Font.Bold = true; Microsoft.Office.Interop.Excel.Range pagada = ws.get_Range("e4", "e4"); pagada.BorderAround2(); pagada.Interior.Color = Color.White; ws.Cells[4, 6] = "Detalle"; ws.Cells[4, 6].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 6].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 6].Font.Bold = true; Microsoft.Office.Interop.Excel.Range detalle = ws.get_Range("f4", "f4"); detalle.BorderAround2(); detalle.Interior.Color = Color.White; ws.Cells[4, 7] = "Razón Social"; ws.Cells[4, 7].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 7].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 7].Font.Bold = true; Microsoft.Office.Interop.Excel.Range razon = ws.get_Range("g4", "g4"); razon.BorderAround2(); razon.Interior.Color = Color.White; ws.Cells[4, 8] = "IVA"; ws.Cells[4, 8].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 8].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 8].Font.Bold = true; Microsoft.Office.Interop.Excel.Range iva = ws.get_Range("h4", "h4"); iva.BorderAround2(); iva.Interior.Color = Color.White; ws.Cells[4, 9] = "Fecha de Pago"; ws.Cells[4, 9].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 9].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 9].Font.Bold = true; Microsoft.Office.Interop.Excel.Range fecha_pago = ws.get_Range("i4", "i4"); fecha_pago.BorderAround2(); fecha_pago.Interior.Color = Color.White; ws.Cells[4, 10] = "Comprobante"; ws.Cells[4, 10].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 10].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 10].Font.Bold = true; Microsoft.Office.Interop.Excel.Range comprobante = ws.get_Range("j4", "j4"); comprobante.BorderAround2(); comprobante.Interior.Color = Color.White; ws.Cells[4, 11] = "Pagada"; ws.Cells[4, 11].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 11].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 11].Font.Bold = true; Microsoft.Office.Interop.Excel.Range fecha_ingreso = ws.get_Range("k4", "k4"); fecha_ingreso.BorderAround2(); fecha_ingreso.Interior.Color = Color.White; //******************** //Empiezo por cantidad //******************** int fila = 5; int columnas = 11; for (int i = 0; i < dgv_tabla.Rows.Count; i++) { for (int j = 0; j < columnas; j++) { if (j == 0) { ws.Cells[fila, 1] = dgv_tabla.Rows[i].Cells["Proveedor"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 1].Borders); } if (j == 1) { ws.Cells[fila, 2] = dgv_tabla.Rows[i].Cells["Motivo"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 2].Borders); } else if (j == 2) { ws.Cells[fila, 3] = dgv_tabla.Rows[i].Cells["Vencimiento"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 3].Borders); //ws.Range[ws.Cells[fila, 2], ws.Cells[fila, 4]].Color = Color.White; } else if (j == 3) { ws.Cells[fila, 4] = dgv_tabla.Rows[i].Cells["Monto"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 4].Borders); // ws.Range[ws.Cells[fila, 5], ws.Cells[fila, 6]].Color = Color.White; } else if (j == 10) { ws.Cells[fila, 5] = dgv_tabla.Rows[i].Cells["Fecha Ingreso"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 5].Borders); //ws.Cells[fila, 7].Color = Color.White; } else if (j == 5) { ws.Cells[fila, 6] = dgv_tabla.Rows[i].Cells["Detalle"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 6].Borders); } else if (j == 6) { ws.Cells[fila, 7] = dgv_tabla.Rows[i].Cells["Razon Social"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 7].Borders); } else if (j == 7) { ws.Cells[fila, 8] = dgv_tabla.Rows[i].Cells["Iva"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 8].Borders); } else if (j == 8) { if (ControladorFuncVariadas.validarDateTimeVacio(Convert.ToDateTime(dgv_tabla.Rows[i].Cells["Fecha Pago"].Value.ToString()))) { ws.Cells[fila, 9] = dgv_tabla.Rows[i].Cells["Fecha Pago"].Value; } else { ws.Cells[fila, 9] = "Pendiente"; } ControladorFuncVariadas.AllBorders(ws.Cells[fila, 9].Borders); } else if (j == 9) { ws.Cells[fila, 10] = dgv_tabla.Rows[i].Cells["Comprobante"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 10].Borders); } else if (j == 4) { if (dgv_tabla.Rows[i].Cells["Pagada"].Value.ToString() == "True") { ws.Cells[fila, 11] = "Sí"; } else { ws.Cells[fila, 11] = "No"; } ControladorFuncVariadas.AllBorders(ws.Cells[fila, 11].Borders); } } fila++; } //ws.Columns[2].NumberFormat = "######"; ws.Columns[4].NumberFormat = "$ #.###,00"; ws.Columns[6].NumberFormat = "$ #.###,00"; ws.Columns[8].NumberFormat = "$ #.###,00"; ws.Columns[3].NumberFormat = "dd/MM/yyyy"; ws.Columns[5].NumberFormat = "dd/MM/yyyy"; ws.Columns[9].NumberFormat = "dd/MM/yyyy"; ws.Columns.AutoFit(); Excel.Interactive = true; Excel.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; } }
public static void armarExcelRendiciones(DataGridView dgv_tabla_venta, DataGridView dgv_tabla_reparacion, DateTime desde, DateTime hasta, string usuario) { ControladorFuncVariadas control = new ControladorFuncVariadas(); Cursor.Current = Cursors.WaitCursor; Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Interactive = false; try { Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = (Worksheet)Excel.ActiveSheet; Excel.WindowState = XlWindowState.xlMaximized; Microsoft.Office.Interop.Excel.Range cabecera = null; ws.Cells[1, 1] = "RENDICIÓN " + usuario; ws.Range[ws.Cells[1, 1], ws.Cells[3, 6]].Merge(); cabecera = ws.get_Range("a1", "f3"); ws.Cells[1, 1].Font.Bold = true; ws.Cells[1, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[1, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[1, 1].Font.Size = 20; cabecera.BorderAround2(); cabecera.Interior.Color = Color.White; ws.Cells[4, 1] = "Entre " + desde.ToString("dd/MM/yyyy") + " y " + hasta.ToString("dd/MM/yyyy"); ws.Range[ws.Cells[4, 1], ws.Cells[4, 6]].Merge(); Range desdehasta = null; desdehasta = ws.get_Range("a4", "f4"); ws.Cells[4, 1].Font.Bold = true; ws.Cells[4, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 1].Font.Size = 11; desdehasta.BorderAround2(); desdehasta.Interior.Color = Color.White; ws.Cells[5, 1] = "ID VENTA"; ws.Cells[5, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[5, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 1].Font.Bold = true; Microsoft.Office.Interop.Excel.Range id_venta = ws.get_Range("a5", "a5"); id_venta.BorderAround2(); id_venta.Interior.Color = Color.White; ws.Cells[5, 2] = "Fecha"; ws.Cells[5, 2].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Cells[5, 2].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 2].Font.Bold = true; Range venta_fecha = ws.get_Range("b5", "b5"); venta_fecha.BorderAround2(); venta_fecha.Interior.Color = Color.White; ws.Cells[5, 3] = "Vendedor"; ws.Cells[5, 3].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[5, 3].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 3].Font.Bold = true; Microsoft.Office.Interop.Excel.Range venta_vendedor = ws.get_Range("c5", "c5"); venta_vendedor.BorderAround2(); venta_vendedor.Interior.Color = Color.White; ws.Cells[5, 4] = "Cliente"; ws.Cells[5, 4].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[5, 4].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 4].Font.Bold = true; Microsoft.Office.Interop.Excel.Range venta_cliente = ws.get_Range("d5", "d5"); venta_cliente.BorderAround2(); venta_cliente.Interior.Color = Color.White; ws.Cells[5, 5] = "Monto"; ws.Cells[5, 5].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[5, 5].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 5].Font.Bold = true; Microsoft.Office.Interop.Excel.Range venta_monto = ws.get_Range("e5", "e5"); venta_monto.BorderAround2(); venta_monto.Interior.Color = Color.White; ws.Cells[5, 6] = "Cobrado"; ws.Cells[5, 6].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[5, 6].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[5, 6].Font.Bold = true; Microsoft.Office.Interop.Excel.Range venta_cobrado = ws.get_Range("f5", "f5"); venta_cobrado.BorderAround2(); venta_cobrado.Interior.Color = Color.White; //******************** //Empiezo por cantidad //******************** int fila = 6; int columnas = 6; for (int i = 0; i < dgv_tabla_venta.Rows.Count; i++) { for (int j = 0; j < columnas; j++) { if (j == 0) { ws.Cells[fila, 1] = dgv_tabla_venta.Rows[i].Cells["Id Venta"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 1].Borders); } else if (j == 1) { ws.Cells[fila, 2] = dgv_tabla_venta.Rows[i].Cells["Fecha"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 2].Borders); } else if (j == 2) { ws.Cells[fila, 3] = dgv_tabla_venta.Rows[i].Cells["Vendedor"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 3].Borders); //ws.Range[ws.Cells[fila, 2], ws.Cells[fila, 4]].Color = Color.White; } else if (j == 3) { ws.Cells[fila, 4] = dgv_tabla_venta.Rows[i].Cells["Cliente"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 4].Borders); // ws.Range[ws.Cells[fila, 5], ws.Cells[fila, 6]].Color = Color.White; } else if (j == 4) { ws.Cells[fila, 5] = dgv_tabla_venta.Rows[i].Cells["Monto"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 5].Borders); //ws.Cells[fila, 7].Color = Color.White; } else if (j == 5) { ws.Cells[fila, 6] = dgv_tabla_venta.Rows[i].Cells["Cobrado"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 6].Borders); } } fila++; } ws.Cells[fila, 1] = "ID REPARACIÓN"; ws.Cells[fila, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[fila, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 1].Font.Bold = true; Microsoft.Office.Interop.Excel.Range id_reparacion = ws.get_Range("a" + fila, "a" + fila); id_reparacion.BorderAround2(); id_reparacion.Interior.Color = Color.White; ws.Cells[fila, 2] = "Fecha"; ws.Cells[fila, 2].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Cells[fila, 2].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 2].Font.Bold = true; Range reparacion_fecha = ws.get_Range("b" + fila, "b" + fila); reparacion_fecha.BorderAround2(); reparacion_fecha.Interior.Color = Color.White; ws.Cells[fila, 3] = "Vendedor"; ws.Cells[fila, 3].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[fila, 3].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 3].Font.Bold = true; Microsoft.Office.Interop.Excel.Range reparacion_vendedor = ws.get_Range("c" + fila, "c" + fila); reparacion_vendedor.BorderAround2(); reparacion_vendedor.Interior.Color = Color.White; ws.Cells[fila, 4] = "Cliente"; ws.Cells[fila, 4].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[fila, 4].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 4].Font.Bold = true; Microsoft.Office.Interop.Excel.Range reparacion_cliente = ws.get_Range("d" + fila, "d" + fila); reparacion_cliente.BorderAround2(); reparacion_cliente.Interior.Color = Color.White; ws.Cells[fila, 5] = "Monto"; ws.Cells[fila, 5].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[fila, 5].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 5].Font.Bold = true; Microsoft.Office.Interop.Excel.Range reparacion_monto = ws.get_Range("e" + fila, "e" + fila); reparacion_monto.BorderAround2(); reparacion_monto.Interior.Color = Color.White; ws.Cells[fila, 6] = "Cobrado"; ws.Cells[fila, 6].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[fila, 6].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[fila, 6].Font.Bold = true; Microsoft.Office.Interop.Excel.Range reparacion_cobrado = ws.get_Range("f" + fila, "f" + fila); reparacion_cobrado.BorderAround2(); reparacion_cobrado.Interior.Color = Color.White; fila++; for (int i = 0; i < dgv_tabla_reparacion.Rows.Count; i++) { for (int j = 0; j < columnas; j++) { if (j == 0) { ws.Cells[fila, 1] = dgv_tabla_reparacion.Rows[i].Cells["Id Venta"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 1].Borders); } else if (j == 1) { ws.Cells[fila, 2] = dgv_tabla_reparacion.Rows[i].Cells["Fecha"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 2].Borders); } else if (j == 2) { ws.Cells[fila, 3] = dgv_tabla_reparacion.Rows[i].Cells["Vendedor"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 3].Borders); //ws.Range[ws.Cells[fila, 2], ws.Cells[fila, 4]].Color = Color.White; } else if (j == 3) { ws.Cells[fila, 4] = dgv_tabla_reparacion.Rows[i].Cells["Cliente"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 4].Borders); // ws.Range[ws.Cells[fila, 5], ws.Cells[fila, 6]].Color = Color.White; } else if (j == 4) { ws.Cells[fila, 5] = dgv_tabla_reparacion.Rows[i].Cells["Monto"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 5].Borders); //ws.Cells[fila, 7].Color = Color.White; } else if (j == 5) { ws.Cells[fila, 6] = dgv_tabla_reparacion.Rows[i].Cells["Cobrado"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 6].Borders); } } fila++; } //ws.Columns[2].NumberFormat = "######"; ws.Columns[5].NumberFormat = "$ #.###,00"; ws.Columns[6].NumberFormat = "$ #.###,00"; ws.Columns.AutoFit(); Excel.Interactive = true; Excel.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; } }
public static void armarExcelReparacionesRealizadas(DataGridView dgv_tabla) { ControladorFuncVariadas control = new ControladorFuncVariadas(); Cursor.Current = Cursors.WaitCursor; Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Interactive = false; try { Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet); Worksheet ws = (Worksheet)Excel.ActiveSheet; Excel.WindowState = XlWindowState.xlMaximized; Microsoft.Office.Interop.Excel.Range cabecera = null; ws.Cells[1, 1] = "Reparaciones Realizadas"; ws.Range[ws.Cells[1, 1], ws.Cells[3, 11]].Merge(); cabecera = ws.get_Range("a1", "k3"); ws.Cells[1, 1].Font.Bold = true; ws.Cells[1, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[1, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[1, 1].Font.Size = 20; cabecera.BorderAround2(); cabecera.Interior.Color = Color.White; ws.Cells[4, 1] = "Razón Social"; ws.Cells[4, 1].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 1].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 1].Font.Bold = true; Microsoft.Office.Interop.Excel.Range razon = ws.get_Range("a4", "a4"); razon.BorderAround2(); razon.Interior.Color = Color.White; ws.Cells[4, 2] = "Máquina"; ws.Cells[4, 2].HorizontalAlignment = XlHAlign.xlHAlignCenter; ws.Cells[4, 2].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 2].Font.Bold = true; Range maquina = ws.get_Range("b4", "b4"); maquina.BorderAround2(); maquina.Interior.Color = Color.White; ws.Cells[4, 3] = "Nro Factura"; ws.Cells[4, 3].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 3].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 3].Font.Bold = true; Microsoft.Office.Interop.Excel.Range nrofactura = ws.get_Range("c4", "c4"); nrofactura.BorderAround2(); nrofactura.Interior.Color = Color.White; ws.Cells[4, 4] = "Tipo"; ws.Cells[4, 4].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 4].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 4].Font.Bold = true; Microsoft.Office.Interop.Excel.Range tipo = ws.get_Range("d4", "d4"); tipo.BorderAround2(); tipo.Interior.Color = Color.White; ws.Cells[4, 5] = "Remito"; ws.Cells[4, 5].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 5].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 5].Font.Bold = true; Microsoft.Office.Interop.Excel.Range remito = ws.get_Range("e4", "e4"); remito.BorderAround2(); remito.Interior.Color = Color.White; ws.Cells[4, 6] = "Total"; ws.Cells[4, 6].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 6].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 6].Font.Bold = true; Microsoft.Office.Interop.Excel.Range total = ws.get_Range("f4", "f4"); total.BorderAround2(); total.Interior.Color = Color.White; ws.Cells[4, 7] = "Fecha"; ws.Cells[4, 7].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 7].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 7].Font.Bold = true; Microsoft.Office.Interop.Excel.Range fecha = ws.get_Range("g4", "g4"); fecha.BorderAround2(); fecha.Interior.Color = Color.White; ws.Cells[4, 8] = "Vencimiento"; ws.Cells[4, 8].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 8].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 8].Font.Bold = true; Microsoft.Office.Interop.Excel.Range vencimiento = ws.get_Range("h4", "h4"); vencimiento.BorderAround2(); vencimiento.Interior.Color = Color.White; ws.Cells[4, 9] = "Fecha Cobro"; ws.Cells[4, 9].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 9].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 9].Font.Bold = true; Microsoft.Office.Interop.Excel.Range fecha_cobro = ws.get_Range("i4", "i4"); fecha_cobro.BorderAround2(); fecha_cobro.Interior.Color = Color.White; ws.Cells[4, 10] = "Vendedor"; ws.Cells[4, 10].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 10].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 10].Font.Bold = true; Microsoft.Office.Interop.Excel.Range vendedor = ws.get_Range("j4", "j4"); vendedor.BorderAround2(); vendedor.Interior.Color = Color.White; ws.Cells[4, 11] = "Cobrada"; ws.Cells[4, 11].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; ws.Cells[4, 11].VerticalAlignment = XlVAlign.xlVAlignCenter; ws.Cells[4, 11].Font.Bold = true; Microsoft.Office.Interop.Excel.Range cobrada = ws.get_Range("k4", "k4"); cobrada.BorderAround2(); cobrada.Interior.Color = Color.White; //******************** //Empiezo por cantidad //******************** int fila = 5; int columnas = 11; for (int i = 0; i < dgv_tabla.Rows.Count; i++) { for (int j = 0; j < columnas; j++) { if (j == 0) { ws.Cells[fila, 1] = dgv_tabla.Rows[i].Cells["Razon Social"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 1].Borders); //ws.Cells[fila, 1].Color = Color.White; } else if (j == 1) { ws.Cells[fila, 2] = dgv_tabla.Rows[i].Cells[2].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 2].Borders); } else if (j == 2) { ws.Cells[fila, 3] = dgv_tabla.Rows[i].Cells["Nro Factura"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 3].Borders); //ws.Range[ws.Cells[fila, 2], ws.Cells[fila, 4]].Color = Color.White; } else if (j == 3) { ws.Cells[fila, 4] = dgv_tabla.Rows[i].Cells["Tipo"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 4].Borders); // ws.Range[ws.Cells[fila, 5], ws.Cells[fila, 6]].Color = Color.White; } else if (j == 4) { ws.Cells[fila, 5] = dgv_tabla.Rows[i].Cells["Remito"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 5].Borders); //ws.Cells[fila, 7].Color = Color.White; } else if (j == 5) { ws.Cells[fila, 6] = dgv_tabla.Rows[i].Cells["Total"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 6].Borders); } else if (j == 6) { ws.Cells[fila, 7] = dgv_tabla.Rows[i].Cells["Fecha"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 7].Borders); } else if (j == 7) { ws.Cells[fila, 8] = dgv_tabla.Rows[i].Cells["Vencimiento"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 8].Borders); } else if (j == 8) { ws.Cells[fila, 9] = dgv_tabla.Rows[i].Cells["Fecha de Cobro"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 9].Borders); } else if (j == 9) { ws.Cells[fila, 10] = dgv_tabla.Rows[i].Cells["Vendedor"].Value; ControladorFuncVariadas.AllBorders(ws.Cells[fila, 10].Borders); } else if (j == 10) { if (dgv_tabla.Rows[i].Cells["Cobrada"].Value.ToString() == "True") { ws.Cells[fila, 11] = "Sí"; } else { ws.Cells[fila, 11] = "No"; } ControladorFuncVariadas.AllBorders(ws.Cells[fila, 11].Borders); } } fila++; } ws.Columns[2].NumberFormat = "######"; ws.Columns[6].NumberFormat = "$ #.###,00"; ws.Columns.AutoFit(); Excel.Interactive = true; Excel.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { Cursor.Current = Cursors.Default; } }