Exemplo n.º 1
0
        private JObject ReadSheetData(IList <SheetFieldInfo> fields, ISheet sheet)
        {
            JObject json_main_obj = new JObject();
            JArray  json_arr      = new JArray();

            //从第四行开始读
            for (var i = 4; i <= sheet.LastRowNum; i++)
            {
                var row = sheet.GetRow(i);
                if (row == null)
                {
                    break;
                }

                var json_obj = new JObject();

                bool break_flag = false;
                foreach (var field in fields)
                {
                    var cell = row.GetCell(field.Index);
                    if (cell == null)
                    {
                        if (field.Key) //key空了,读到这里就停止
                        {
                            break_flag = true;
                            break;
                        }
                        else
                        {
                            //非key的是数据空了,使用默认值或者跳过
                            if (InsertDefaultValueIfNoData)
                            {
                                json_obj.Add(NekoUtil.GetDefaultValue(field.Name, field.Type, field.ArrayType));
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        json_obj.Add(NekoUtil.GetJsonProperty(field.Name, cell.ToString(), field.Type, field.ArrayType, SplitChar));
                    }
                }

                if (break_flag)
                {
                    break;
                }

                json_arr.Add(json_obj);
            }

            json_main_obj.Add(new JProperty(JsonRootNodeName, json_arr));

            return(json_main_obj);
        }
Exemplo n.º 2
0
 public void GetDefaultJsonValueTest()
 {
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.String, Enums.FieldType.String).ToString());
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.Number, Enums.FieldType.String).ToString());
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.Boolean, Enums.FieldType.String).ToString());
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.Array, Enums.FieldType.String).ToString());
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.Array, Enums.FieldType.Number).ToString());
     TestContext.WriteLine(NekoUtil.GetDefaultValue("test", Enums.FieldType.Array, Enums.FieldType.Boolean).ToString());
     Assert.Pass();
 }