Пример #1
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())));
        }
Пример #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())));
        }
Пример #3
0
 private static IEnumerable <Entry> GetHskListForLevel(string fileName)
 {
     using (var list = typeof(PopupChineseHskWordListImporter).GetEmbeddedFile(fileName))
     {
         var helper = new ExcelDataReaderHelper(list);
         foreach (var row in helper.GetRangeCells(0, 2, 2, 5))
         {
             var result = new Entry
             {
                 Simplified  = (string)row[0],
                 Traditional = (string)row[1],
                 Pinyin      = SplitPinyin((string)row[2]),
                 Definition  = (string)row[3]
             };
             result.AddPartOfSpeech((string)row[4]);
             yield return(result);
         }
     }
 }