private void mostrarFila(object sender, EventArgs e) { exportaContaSis.RowProcessedEventArgs argumentos = (exportaContaSis.RowProcessedEventArgs)e; if (pgbProceso.Maximum == 0) { pgbProceso.Maximum = argumentos.total; } pgbProceso.Value = argumentos.numero; //.ToString(); Application.DoEvents(); }
private bool generaExcel2(string ruta) { try { if (File.Exists(ruta + "regventas.xls") == true) { File.Delete(ruta + "regventas.xls"); } Excel.Application myApp; Excel.Workbook myWorkBk; object missingValue = System.Reflection.Missing.Value; myApp = new Microsoft.Office.Interop.Excel.Application(); myApp.Visible = false; myWorkBk = myApp.Workbooks.Add(missingValue); Excel.Worksheet myWorkSht; myWorkSht = (Excel.Worksheet)myWorkBk.Worksheets.get_Item(1); myWorkSht.Name = "RegVentas"; int nroFilas = 0; int nroColumnas = 0; nroFilas = datos.Rows.Count; nroColumnas = datos.Columns.Count; Excel.Range rango; for (int i = 1; i <= nroFilas; i++) { RowProcessedEventArgs argumentos = new RowProcessedEventArgs(); argumentos.numero = i; argumentos.total = nroFilas; filaprocesada(this, argumentos); for (int j = 1; j < nroColumnas; j++) { //poner el valor en la celda //formato de texto switch (j) { case 1: case 2: case 18: case 24: case 36: rango = myWorkSht.Range[myWorkSht.Cells[i, j], myWorkSht.Cells[i, j]]; rango.NumberFormat = "dd/mm/yyyy"; break; case 3: case 4: case 5: case 6: case 7: case 8: case 19: case 20: case 21: case 22: case 25: case 26: case 27: case 28: case 29: case 30: case 34: case 35: case 37: case 39: rango = myWorkSht.Range[myWorkSht.Cells[i, j], myWorkSht.Cells[i, j]]; rango.NumberFormat = "@"; break; case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 23: case 32: case 33: case 38: rango = myWorkSht.Range[myWorkSht.Cells[i, j], myWorkSht.Cells[i, j]]; rango.NumberFormat = "0.00"; break; case 17: rango = myWorkSht.Range[myWorkSht.Cells[i, j], myWorkSht.Cells[i, j]]; rango.NumberFormat = "0.0000"; break; } if (cancelaProceso == true) { return(false); } myWorkSht.Cells[i, j] = datos.Rows[i - 1][j - 1]; } } myWorkSht.SaveAs(ruta + "regventas.xls"); myApp.Visible = true; return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } }