示例#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);
        }
示例#2
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);
        }