Пример #1
0
        private CellValue GetCellValue(Cell cell, FieldInfo fieldInfo)
        {
            String text = GetTextInCell(cell);

            if (text == "")
            {
                if (fieldInfo.DataType == DataType.Int)
                    return new CellValue(fieldInfo, (Int32)0);

                if (fieldInfo.DataType == DataType.Double)
                    return new CellValue(fieldInfo, (Double)0);

                return new CellValue(fieldInfo, null);
            }

            else if (fieldInfo.DataType == DataType.DateTime)
            {
                DateTime value;
                Double dblValue;

                if (DateTime.TryParse(text, out value) == true)
                    return new CellValue(fieldInfo, value);

                else if (Double.TryParse(text, out dblValue) == true)
                    return new CellValue(fieldInfo, DateTime.FromOADate(dblValue));

                else
                    throw new AegisException("Invalid data at {0}.{1}", _sheet.Name, cell.CellReference);
            }

            else if (fieldInfo.DataType == DataType.Int)
            {
                Int32 value;
                if (Int32.TryParse(text, out value) == true)
                    return new CellValue(fieldInfo, value);

                else
                    throw new AegisException("Invalid data at {0}.{1}", _sheet.Name, cell.CellReference);
            }

            else if (fieldInfo.DataType == DataType.Double)
            {
                Double value;
                if (Double.TryParse(text, out value) == true)
                    return new CellValue(fieldInfo, value);

                else
                    throw new AegisException("Invalid data at {0}.{1}", _sheet.Name, cell.CellReference);
            }

            else
                return new CellValue(fieldInfo, text);
        }
Пример #2
0
 internal CellValue(FieldInfo field, dynamic value)
 {
     _field = field;
     _value = value;
 }
Пример #3
0
        public ExcelSheet Load()
        {
            WorkbookPart wbp = _parent.Workbook.WorkbookPart;
            WorksheetPart wsp = (WorksheetPart)wbp.GetPartById(_sheet.Id.Value);
            SheetData sheetData = wsp.Worksheet.GetFirstChild<SheetData>();

            _iter = sheetData.Elements<Row>().GetEnumerator();
            _sstp = wbp.GetPartsOfType<SharedStringTablePart>().First();
            _rowCount = sheetData.Elements<Row>().Count();
            _maxRowIndex = sheetData.Elements<Row>().Max(v => v.RowIndex.Value);

            //  Field 정보
            if (_parent.RowIndex_FieldName >= 0)
            {
                Row row;
                Int32 idx;

                //  Field name
                idx = 0;
                row = sheetData.Elements<Row>().Where(v => v.RowIndex == _parent.RowIndex_FieldName).FirstOrDefault();
                if (row == null)
                    throw new AegisException("FieldName index is {0}, but {1} has no {0} row index.", _parent.RowIndex_FieldName, _sheet.Name);
                _fields = new FieldInfo[row.LongCount()];

                foreach (Cell cell in row.Elements<Cell>())
                {
                    _fields[idx] = new FieldInfo();
                    _fields[idx].Name = GetTextInCell(cell);
                    ++idx;
                }

                //  Field data type
                idx = 0;
                row = sheetData.Elements<Row>().Where(v => v.RowIndex == _parent.RowIndex_DataType).First();
                foreach (Cell cell in row.Elements<Cell>())
                {
                    String text = GetTextInCell(cell).ToLower();

                    if (text == "int" || text == "integer")
                        _fields[idx++].DataType = DataType.Int;

                    else if (text == "double")
                        _fields[idx++].DataType = DataType.Double;

                    else if (text == "datetime")
                        _fields[idx++].DataType = DataType.DateTime;

                    else if (text == "string")
                        _fields[idx++].DataType = DataType.String;

                    else
                        throw new AegisException("Invalid field type at {0}.{1}", _sheet.Name, cell.CellReference);
                }
            }

            return this;
        }