Beispiel #1
0
        public static IEnumerable <GoalExcel> ReadFromXLSX(string fullPath)
        {
            List <GoalExcel> result = new List <GoalExcel>();

            using (var stream = File.OpenRead(fullPath))
            {
                using (ExcelDataReaderHelper excelHelper = new ExcelDataReaderHelper(stream))
                {
                    result = excelHelper.GetRange <GoalExcel>(0, 1, 1).ToList();
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Example method showing how to use the <see cref="Excel.ExcelReaderHelper"/> for reading:
        /// - Untyped jagged array using <see cref="GetRangeCells"/>
        /// - Typed jagged array using <see cref="GetRangeCells<T>"/>
        /// - Typed objects with values mapped to properties using <see cref="GetRange<T>"/>
        /// </summary>
        /// <param name="excelHelper">The <see cref="Excel.Helper.ExcelDataReaderHelper"/>.</param>
        static void ReadExcelExample(ExcelDataReaderHelper excelHelper)
        {
            // worksheet info
            Console.WriteLine("\nNumber of Worksheets: {0} ({1})", excelHelper.WorksheetCount, string.Join(", ", excelHelper.WorksheetNames));

            // values
            Console.WriteLine("\nValues from sheet 'values':");
            object[][] values = excelHelper.GetRangeCells("values", 1, 1);
            Console.WriteLine(string.Join("\n", values.Select(rowValues => string.Join(", ", rowValues))));

            // numbers
            Console.WriteLine("\nInt values from sheet 'numbers':");
            int[][] numbers = excelHelper.GetRangeCells <int>("numbers", 1, 1);
            Console.WriteLine(string.Join("\n", numbers.Select(rowValues => string.Join(", ", rowValues))));

            // orders
            Console.WriteLine("\nOrders from sheet 'orders':");
            Order[] orders = excelHelper.GetRange <Order>("orders", 1, 3);
            Console.WriteLine(string.Join("\n", orders.Select(x => x.ToString())));
        }
        /// <summary>
        /// Example method showing how to use the <see cref="Excel.ExcelReaderHelper"/> for reading:
        /// - Untyped jagged array using <see cref="GetRangeCells"/>
        /// - Typed jagged array using <see cref="GetRangeCells<T>"/>
        /// - Typed objects with values mapped to properties using <see cref="GetRange<T>"/>
        /// </summary>
        /// <param name="excelHelper">The <see cref="Excel.Helper.ExcelDataReaderHelper"/>.</param>
        static void ReadExcelExample(ExcelDataReaderHelper excelHelper)
        {
            // worksheet info
            Console.WriteLine ("\nNumber of Worksheets: {0} ({1})", excelHelper.WorksheetCount, string.Join (", ", excelHelper.WorksheetNames));

            // values
            Console.WriteLine("\nValues from sheet 'values':");
            object[][] values = excelHelper.GetRangeCells("values", 1, 1);
            Console.WriteLine(string.Join("\n", values.Select(rowValues => string.Join(", ", rowValues))));

            // numbers
            Console.WriteLine("\nInt values from sheet 'numbers':");
            int[][] numbers = excelHelper.GetRangeCells<int>("numbers", 1, 1);
            Console.WriteLine(string.Join("\n", numbers.Select(rowValues => string.Join(", ", rowValues))));

            // orders
            Console.WriteLine("\nOrders from sheet 'orders':");
            Order[] orders = excelHelper.GetRange<Order>("orders", 1, 3);
            Console.WriteLine(string.Join("\n", orders.Select(x => x.ToString())));
        }