コード例 #1
0
 private DateTime?ExtractDateTime(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(TypeConvert.ToDateTimeNull(row.Cells[index]));
     }
     else
     {
         return(null);
     }
 }
コード例 #2
0
 private string ExtractText(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(row.TextCells[index]);
     }
     else
     {
         return(String.Empty);
     }
 }
コード例 #3
0
 private double ExtractDouble(XlsRowData row, string column)
 {
     if (ColumnIndex.ContainsKey(column))
     {
         var index = ColumnIndex[column];
         return(TypeConvert.ToDouble(row.Cells[index]));
     }
     else
     {
         return(0);
     }
 }
コード例 #4
0
        private XlsSheetData ReadSheet(IExcelDataReader reader)
        {
            var cols  = new List <XlsColumnData>();
            var rows  = new List <XlsRowData>();
            var sheet = new XlsSheetData()
            {
                SheetName = reader.Name,
                Columns   = cols,
                Rows      = rows
            };

            //var header = reader.HeaderFooter;
            var count = reader.FieldCount;

            for (var col = 0; col < count; col++)
            {
                var data = typeof(object);
                var name = col.ToString();
                cols.Add(new XlsColumnData()
                {
                    Name     = name,
                    DataType = data
                });
            }

            while (reader.Read())
            {
                var row   = new XlsRowData();
                var cells = new object[count];
                for (var col = 0; col < count; col++)
                {
                    cells[col] = reader.GetValue(col);
                }
                row.Cells = cells;
                rows.Add(row);
            }

            return(sheet);
        }