Ejemplo n.º 1
0
        private void ReadProperties(XlsxSheet sheet)
        {
            mNamespace = sheet.SheetName;
            mId        = sheet.SheetName;
            Properties client = new Properties(sheet, DataSideEnum.C, CLIENT_XLSX_NODE_TAG, this);
            Properties server = new Properties(sheet, DataSideEnum.S, SERVER_XLSX_NODE_TAG, this);

            mNamespaces.Add(client);
            mNamespaces.Add(server);
        }
Ejemplo n.º 2
0
        private Properties(XlsxSheet sheet, DataSideEnum side, string name, Properties parent) : this()
        {
            mNamespace = name;
            mId        = name;
            mParent    = parent;
            List <int> cols = sheet.GetColumns(side);

            for (int i = 0; i < sheet.RowCount; ++i)
            {
                Properties rowProp = new Properties(sheet, i, cols, sheet.SheetName, this);
                mNamespaces.Add(rowProp);
            }
        }
Ejemplo n.º 3
0
        public static XlsxSheet Create(ExcelWorksheet tDS, Xlsx parent)
        {
            XlsxSheet           sheet = new XlsxSheet(parent, tDS.Name);
            List <string>       variableNames;
            List <DataTypeEnum> variableTypes;
            List <DataSideEnum> variableSides;
            string managerName = null;
            string keys        = null;

            MainEntry.Log(string.Format("-------------------SheetName: {0} Begin", tDS.Name));
            List <XlsxRow> datas = CleanRowAndCols(tDS, sheet, out managerName, out keys, out variableNames, out variableTypes, out variableSides);

            if (datas != null)
            {
                sheet.Set(managerName, keys, variableNames, variableTypes, variableSides, datas);
                MainEntry.Log(string.Format("-------------------SheetName: {0} End", tDS.Name));
                return(sheet);
            }
            MainEntry.Log(string.Format("*******************SheetName: {0} failed", tDS.Name));
            return(null);
        }
Ejemplo n.º 4
0
 private Properties(XlsxSheet sheet, int row, List <int> cols, string name, Properties parent) : this()
 {
     mNamespace = name;
     mId        = name;
     mParent    = parent;
     for (int i = 0; i < cols.Count; ++i)
     {
         int          colIndex = cols[i];
         string       varName  = null;
         DataTypeEnum varType  = DataTypeEnum.NONE;
         sheet.GetCol(colIndex, ref varName, ref varType);
         string value = sheet[row, colIndex];
         if (value != null)
         {
             string defaultValue = null;
             switch (varType)
             {
             case DataTypeEnum.BYTE:
             case DataTypeEnum.SHORT:
             case DataTypeEnum.USHORT:
             case DataTypeEnum.INT:
             case DataTypeEnum.UINT:
             case DataTypeEnum.LONG:
             case DataTypeEnum.ULONG:
             case DataTypeEnum.FLOAT:
                 defaultValue = "0";
                 break;
             }
             // 默认值不导出
             if (defaultValue != null && defaultValue.Equals(value))
             {
                 continue;
             }
             mProperties.Add(new Property(varName, value));
         }
     }
 }
Ejemplo n.º 5
0
        private static List <XlsxRow> CleanRowAndCols(ExcelWorksheet tDS, XlsxSheet sheet, out string managerName, out string keys, out List <string> variableNames, out List <DataTypeEnum> variableTypes, out List <DataSideEnum> variableSides)
        {
            variableNames = new List <string>();
            variableTypes = new List <DataTypeEnum>();
            variableSides = new List <DataSideEnum>();
            managerName   = null;
            keys          = null;
            ExcelRange range = tDS.Cells;

            object[,] values = (object[, ])range.Value;
            int           rows     = values.GetLength(0);
            int           cols     = values.GetLength(1);
            HashSet <int> skipCols = new HashSet <int>();
            HashSet <int> skipRows = new HashSet <int>();

            if (rows > 0 && cols > 0)
            {
                // List,Group<ColName>,Map<ColName>,Map<ColName1, ColName2>
                string value = (string)values[SHEET_DATA_MANAGER, 0];
                if (value == null)
                {
                    MainEntry.Log(string.Format("****************SheetName: {0} Wrong At [0, 0] End", tDS.Name));
                    return(null);
                }
                ParseManagerType(value, ref managerName, ref keys);
                if (managerName == null)
                {
                    MainEntry.Log(string.Format("****************SheetName: {0} Wrong ManagerName {1} End", tDS.Name, value));
                    return(null);
                }
            }
            for (int i = 0; i < cols; ++i)
            {
                if (values[VARIABLE_SIDE_ROW, i] == null)
                {
                    MainEntry.Log(string.Format("skip null col: [{0}, {1}], maybe last col", VARIABLE_SIDE_ROW, i));
                    skipCols.Add(i);
                    continue;
                }
                string       v    = values[VARIABLE_SIDE_ROW, i].ToString().Trim().ToUpper();
                DataSideEnum side = EnumUtils.StringToEnum <DataSideEnum>(v);
                if (side == DataSideEnum.SKIP)
                {
                    MainEntry.Log(string.Format("skip flag col: [{0}, {1}]", VARIABLE_SIDE_ROW, i));
                    skipCols.Add(i);
                    continue;
                }
                if (values[VARIABLE_NAME_ROW, i] == null)
                {
                    // log
                    MainEntry.Log(string.Format("Not Define Variable Name: [{0}, {1}]", VARIABLE_NAME_ROW, i));
                    return(null);
                }
                if (values[VARIABLE_TYPE_ROW, i] == null)
                {
                    // log
                    MainEntry.Log(string.Format("Not Define Variable Type: [{0}, {1}]", VARIABLE_TYPE_ROW, i));
                    return(null);
                }
                variableSides.Add(side);
                v = values[VARIABLE_NAME_ROW, i].ToString().Trim();
                variableNames.Add(v);
                v = values[VARIABLE_TYPE_ROW, i].ToString().Trim();
                try
                {
                    DataTypeEnum dataType = EnumUtils.StringToEnum <DataTypeEnum>(v.ToUpper());
                    variableTypes.Add(dataType);
                }
                catch (Exception e)
                {
                    MainEntry.Log(string.Format("Not Define Variable Side: [{0}, {1}] = {2}, Error: {3}", VARIABLE_TYPE_ROW, i, v, e.Message));
                    return(null);
                }
            }
            for (int i = VALUE_START_ROW; i < rows; ++i)
            {
                if (values[i, 0] != null)
                {
                    string v = values[i, 0].ToString().Trim();
                    if (v.StartsWith(SKIP_ROW))
                    {
                        MainEntry.Log(string.Format("skip flag row: [{0}, 0]", i));
                        skipRows.Add(i);
                    }
                }
                else
                {
                    MainEntry.Log(string.Format("skip null row: [{0}, 0], maybe last row", i));
                    skipRows.Add(i);
                }
            }
            List <XlsxRow> originalDatas = new List <XlsxRow>();
            int            rowIndex      = 0;

            for (int i = VALUE_START_ROW; i < rows; ++i)
            {
                if (skipRows.Contains(i))
                {
                    continue;
                }
                List <string> rowData = new List <string>();
                XlsxRow       row     = new XlsxRow(rowIndex++, rowData, sheet);
                originalDatas.Add(row);
                for (int j = 0; j < cols; ++j)
                {
                    if (skipCols.Contains(j))
                    {
                        continue;
                    }
                    rowData.Add(values[i, j] != null ? values[i, j].ToString() : null);
                }
            }
            return(originalDatas);
        }
Ejemplo n.º 6
0
 public XlsxRow(int rowIndex, List <string> v, XlsxSheet parent)
 {
     RowIndex = rowIndex;
     Values   = v;
     Parent   = parent;
 }
Ejemplo n.º 7
0
 private Properties(XlsxSheet sheet, Properties parent) : this()
 {
     mParent = parent;
     ReadProperties(sheet);
     Rewind();
 }