Example #1
0
        public void EscribirDatosHoja(string[,] datos, string nombreHoja)
        {
            if (datos != null && datos.Length > 0 && !string.IsNullOrEmpty(nombreHoja))
            {
                bool            siExisteHoja = ComprobarSiExisteHoja(nombreHoja, out int indiceHoja);
                Excel.Worksheet hojaActual   = null;

                if (!siExisteHoja)
                {
                    hojaActual      = LibroExcel.Worksheets.Add();
                    hojaActual.Name = nombreHoja;
                    Hojas           = ObtenerLibroYHojasDelLibro(LibroExcel);
                }
                else
                {
                    hojaActual = LibroExcel.Worksheets[indiceHoja];
                }

                int numeroFilas    = datos.GetLength(0);
                int numeroColumnas = datos.GetLength(1);

                Excel.Range rango = (Excel.Range)hojaActual.Range[hojaActual.Cells[1, 1], hojaActual.Cells[numeroFilas, numeroColumnas]];

                rango.Value2 = datos;

                //for(int i = 0; i < numeroFilas; i++)
                //{
                //    for(int j = 0; j < numeroColumnas; j++)
                //    {
                //        hojaActual.Cells[i + 1, j + 1] = datos[i, j];
                //    }
                //}

                LibroExcel.Save();
            }
        }
Example #2
0
 public void CerrarLibroExcel()
 {
     LibroExcel.Save();
     LibroExcel.Close();
 }