Example #1
0
        public static void WriteSchema(Schema schema, ISheet sheet, HeadModel headModel, int schemaColOffset = 0)
        {
            if (schema == null || sheet == null)
            {
                return;
            }

            //first row is name
            IRow NameRow = sheet.CreateRow(sheet.FirstRowNum + headModel.NameRow);
            //second row is data type
            IRow typeRow = sheet.CreateRow(sheet.FirstRowNum + headModel.DataTypeRow);

            bool haveDescription = headModel.DescriptionRow != -1;
            bool haveSide        = headModel.SideRow != -1;
            //third row is description
            IRow descriptionRow = null;

            if (haveDescription)
            {
                descriptionRow = sheet.CreateRow(sheet.FirstRowNum + headModel.DescriptionRow);
            }

            IRow sideRow = null;

            if (haveSide)
            {
                sideRow = sheet.CreateRow(sheet.FirstRowNum + headModel.SideRow);
            }

            for (int i = 0, l = schema.fields.Count; i < l; ++i)
            {
                int   col   = i + schemaColOffset;
                Field field = schema.fields[i];
                //name
                ICell nameCell = NameRow.CreateCell(col, CellType.String);
                nameCell.SetCellValue(field.name);

                //type cell
                ICell typeCell = typeRow.CreateCell(col, CellType.String);
                typeCell.SetCellValue(field.type.ToString());

                //description
                if (haveDescription)
                {
                    ICell descriptionCell = descriptionRow.CreateCell(col, CellType.String);
                    descriptionCell.SetCellValue(field.description);
                }

                //side
                if (haveSide)
                {
                    ICell sideCell = sideRow.CreateCell(col, CellType.String);
                    sideCell.SetCellValue(field.side.ToString());
                }
            }
        }
Example #2
0
 public void WriteDictionary(ISheet sheet, Schema schema, IDictionary data, HeadModel headModel)
 {
     WriteDictionary(sheet, schema, data, headModel.DataRow, 0, null);
 }
Example #3
0
 public void WriteList(ISheet sheet, Schema schema, IList list, HeadModel headModel)
 {
     WriteList(sheet, schema, list, headModel.DataRow, 0, null);
 }
Example #4
0
 public IDictionary ReadDictionary(ISheet sheet, Schema schema, string keyField, HeadModel headModel)
 {
     return(ReadDictionary(sheet, schema, keyField, headModel.DataRow, 0, -1, null));
 }
Example #5
0
 public IDictionary ReadDictionary(ISheet sheet, Schema schema, HeadModel headModel)
 {
     return(ReadDictionary(sheet, schema, "", headModel.DataRow, 0, -1, null));
 }
Example #6
0
 public List <object> ReadList(ISheet sheet, Schema schema, HeadModel headModel)
 {
     return(ReadList(sheet, schema, headModel.DataRow, -1, 0, -1, null));
 }
Example #7
0
        public static Schema ReadSchema(ISheet sheet, HeadModel headModel, int schemaColOffset = 0)
        {
            Schema schema = new Schema();

            schema.name = sheet.SheetName;

            //first row is name
            IRow NameRow = sheet.GetRow(sheet.FirstRowNum + headModel.NameRow);
            //second row is data type
            IRow typeRow = sheet.GetRow(sheet.FirstRowNum + headModel.DataTypeRow);

            bool haveDescription = headModel.DescriptionRow != -1;
            bool haveSide        = headModel.SideRow != -1;
            //thirdrow is description
            IRow descriptionRow = null;

            if (haveDescription)
            {
                descriptionRow = sheet.GetRow(sheet.FirstRowNum + headModel.DescriptionRow);
            }

            IRow sideRow = null;

            if (haveSide)
            {
                sideRow = sheet.GetRow(sheet.FirstRowNum + headModel.SideRow);
            }

            for (int i = NameRow.FirstCellNum + schemaColOffset; i < NameRow.LastCellNum; ++i)
            {
                //get name
                ICell  nameCell = NameRow.GetCell(i);
                string name     = nameCell.StringCellValue;

                //get type
                TypeInfo dataType = TypeInfo.Object;
                ICell    typeCell = typeRow.GetCell(i);
                if (typeCell != null)
                {
                    dataType = TypeInfo.Parse(typeCell.StringCellValue);
                }

                //get description
                string description = "";
                if (haveDescription)
                {
                    ICell descriptionCell = descriptionRow.GetCell(i);
                    description = descriptionCell.StringCellValue;
                }

                //get comment
                string comment = "";
                if (nameCell.CellComment != null)
                {
                    comment = nameCell.CellComment.String.String;
                }

                Side side = Side.All;
                if (haveSide)
                {
                    ICell  sideCell  = sideRow.GetCell(i);
                    string sideValue = ReadHelper.GetStringValue(sideCell);
                    if (!string.IsNullOrEmpty(sideValue))
                    {
                        side = (Side)System.Enum.Parse(typeof(Side), sideValue);
                    }
                }

                Field field = new Field(name, dataType, comment, description, side);
                schema.AddField(field);
            }

            return(schema);
        }