예제 #1
0
        public void leermatriz()
        {
            //LEO LA MATRIZ QUE TENGO EN EXCEL PARAA IMPRIMIRLA

            var estruc = new clsEstructura().cargaDatosXLS();


            Console.WriteLine("Leer Matriz del Archivo de Excel\n");
            foreach (var excel in estruc)
            {
                matrix[rows, 0] = excel.matric1;
                matrix[rows, 1] = excel.matric2;
                matrix[rows, 2] = excel.matric3;
                Console.WriteLine(" \t" + matrix[rows, 0] + "\t" + matrix[rows, 1] + "\t" + matrix[rows, 2] + "\n");

                rows++;
            }
        }
예제 #2
0
        public List <clsEstructura> cargaDatosXLS()
        {
            Excel.Application xlApp;
            Excel.Workbook    xlWorkBook;
            Excel.Worksheet   xlWorkSheet;
            Excel.Range       range;

            int rCnt;
            int rw = 0;
            int cl = 0;

            xlApp       = new Excel.Application();
            xlWorkBook  = xlApp.Workbooks.Open(@"C:\Users\Jefferson Rueda\Desktop\5TO SEMESTRE\PROGRAMACION 3\matriz1.xlsx");
            xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

            range = xlWorkSheet.UsedRange;
            rw    = range.Rows.Count;
            cl    = range.Columns.Count;

            List <clsEstructura> todos      = new List <clsEstructura>();
            clsEstructura        individual = new clsEstructura();

            for (rCnt = 1; rCnt <= rw; rCnt++)
            {
                individual.matric1 = (int)(range.Cells[rCnt, 1] as Excel.Range).Value2;
                individual.matric2 = (int)(range.Cells[rCnt, 2] as Excel.Range).Value2;
                individual.matric3 = (int)(range.Cells[rCnt, 3] as Excel.Range).Value2;



                todos.Add(individual);
                individual = new clsEstructura();
            }

            xlWorkBook.Close(true, null, null);
            xlApp.Quit();

            Marshal.ReleaseComObject(xlWorkSheet);
            Marshal.ReleaseComObject(xlWorkBook);
            Marshal.ReleaseComObject(xlApp);

            return(todos);
        }