Beispiel #1
0
        public static Dictionary <string, object> ReadDictionary(ISheet sheet, Schema schema, string keyField, int dataStartOffset, int colStartOffset, List <string> header, bool removeKeyInElement = false)
        {
            if (header == null || header.Count == 0)
            {
                header = EDReadHelper.GetHeader(sheet, 0, colStartOffset);
            }

            List <Field> headerFields = EDReadHelper.PrepareHeaderFields(header, schema);

            //如果没指定key,则默认使用第一个
            if (string.IsNullOrEmpty(keyField))
            {
                keyField = header[0];
            }

            Dictionary <string, object> dict = new Dictionary <string, object>();

            for (int i = sheet.FirstRowNum + dataStartOffset; i <= sheet.LastRowNum; ++i)
            {
                Dictionary <string, object> record = ReadRowData(sheet.GetRow(i), headerFields, colStartOffset);
                string key = record[keyField].ToString();
                dict[key] = record;
                if (removeKeyInElement)
                {
                    record.Remove(keyField);
                }
            }
            return(dict);
        }
Beispiel #2
0
        public static object GetCellValue(ICell cell, ExcelDataType dataType)
        {
            switch (dataType)
            {
            case ExcelDataType.Int:
                return(EDReadHelper.GetIntValue(cell));

            case ExcelDataType.Float:
                return(EDReadHelper.GetFloatValue(cell));

            case ExcelDataType.Long:
                return(EDReadHelper.GetLongValue(cell));

            case ExcelDataType.Double:
                return(EDReadHelper.GetDoubleValue(cell));

            case ExcelDataType.Boolean:
                return(EDReadHelper.GetBoolValue(cell));

            case ExcelDataType.String:
                return(EDReadHelper.GetStringValue(cell));

            case ExcelDataType.Array:
            default:
                break;
            }
            return(null);
        }
Beispiel #3
0
        static List <double> GetListDouble(ISheet sheet, int rowIndex, int colIndex)
        {
            List <double> list = new List <double>();

            for (int i = sheet.FirstRowNum + rowIndex; i <= sheet.LastRowNum; ++i)
            {
                IRow  row  = sheet.GetRow(i);
                ICell cell = row.GetCell(row.FirstCellNum + colIndex);
                list.Add(EDReadHelper.GetDoubleValue(cell));
            }
            return(list);
        }
Beispiel #4
0
        static List <T> GetPrimitiveList <T>(ISheet sheet, int rowIndex, int colIndex, ExcelDataType dataType)
        {
            List <T> list = new List <T>();

            for (int i = sheet.FirstRowNum + rowIndex; i <= sheet.LastRowNum; ++i)
            {
                IRow  row  = sheet.GetRow(i);
                ICell cell = row.GetCell(row.FirstCellNum + colIndex);
                list.Add((T)EDReadHelper.GetCellValue(cell, dataType));
            }
            return(list);
        }
Beispiel #5
0
        public static List <object> ReadList(ISheet sheet, Schema schema, int dataStartOffset, int colStartOffset, List <string> header)
        {
            if (header == null || header.Count == 0)
            {
                header = EDReadHelper.GetHeader(sheet, 0, colStartOffset);
            }

            List <Field> headerFields = EDReadHelper.PrepareHeaderFields(header, schema);

            List <object> list = new List <object>();

            for (int i = sheet.FirstRowNum + dataStartOffset; i <= sheet.LastRowNum; ++i)
            {
                Dictionary <string, object> record = ReadRowData(sheet.GetRow(i), headerFields, colStartOffset);
                list.Add(record);
            }
            return(list);
        }
Beispiel #6
0
        public static object GetCellValue(ICell cell, Field field)
        {
            if (cell != null)
            {
                switch (field.type)
                {
                case ExcelDataType.Int:
                    return(EDReadHelper.GetIntValue(cell));

                case ExcelDataType.Float:
                    return(EDReadHelper.GetFloatValue(cell));

                case ExcelDataType.Long:
                    return(EDReadHelper.GetLongValue(cell));

                case ExcelDataType.Double:
                    return(EDReadHelper.GetDoubleValue(cell));

                case ExcelDataType.Boolean:
                    return(EDReadHelper.GetBoolValue(cell));

                case ExcelDataType.String:
                    return(EDReadHelper.GetStringValue(cell));

                case ExcelDataType.List:
                    return(EDLinkDataReader.GetLinkData(cell, field.ExtTypeToSystemType()));

                case ExcelDataType.Array:
                    return(EDLinkDataReader.GetLinkArray(cell, field.ExtTypeToSystemType()));

                case ExcelDataType.Dictionary:
                    return(EDLinkDataReader.GetLinkDict(cell, field.extTypeKeyField, field.extType.IndexOf("RemoveKey") > -1));

                default:
                    break;
                }
            }
            return(null);
        }