예제 #1
0
        /// <summary>
        /// 获取表格数据
        /// </summary>
        /// <param name="grid">表格</param>
        /// <returns>流</returns>
        public byte[] GetBytes(GridA grid)
        {
            Binary br = new Binary();

            br.WriteString(grid.Name);
            List <GridColumn> columns = grid.GetColumns();
            int columnsSize           = columns.Count;

            br.WriteInt(columnsSize);
            for (int i = 0; i < columnsSize; i++)
            {
                GridColumn column = columns[i];
                br.WriteString(column.Name);
                br.WriteString(column.ColumnType);
            }
            List <GridRow> rows      = grid.GetRows();
            int            rowsCount = rows.Count;

            br.WriteInt(rowsCount);
            for (int i = 0; i < rowsCount; i++)
            {
                GridRow row = rows[i];
                for (int j = 0; j < columnsSize; j++)
                {
                    GridColumn column     = columns[j];
                    String     columnType = column.ColumnType.ToLower();
                    GridCell   cell       = row.GetCell(j);
                    if (columnType == "bool")
                    {
                        br.WriteBool(cell.GetBool());
                    }
                    else if (columnType == "double")
                    {
                        br.WriteDouble(cell.GetDouble());
                    }
                    else if (columnType == "float")
                    {
                        br.WriteFloat(cell.GetFloat());
                    }
                    else if (columnType == "int")
                    {
                        br.WriteInt(cell.GetInt());
                    }
                    else if (columnType == "long")
                    {
                        br.WriteDouble(cell.GetLong());
                    }
                    else if (columnType == "string")
                    {
                        br.WriteString(cell.GetString());
                    }
                }
            }
            byte[] bytes = br.GetBytes();
            br.Close();
            return(bytes);
        }