Exemplo n.º 1
0
        /// <summary>
        /// 添加字段信息
        /// </summary>
        /// <param name="fieldInfo"></param>
        public void AddFieldInfo(ExcelFieldInfo fieldInfo)
        {
            if (fieldInfo == null)
            {
                return;
            }

            FieldInfos.Add(fieldInfo);
        }
        /// <summary>
        /// 获取工作簿,读取表头信息,
        /// </summary>
        /// <param name="Excel文件路径"></param>
        private void InitSheetInfo(ExcelScriptExportSetting exportSetting)
        {
            string excelFilePath = exportSetting.TaregetExcel;
            var    readRule      = exportSetting.readRule;

            using (var fs = new FileStream(excelFilePath, FileMode.Open, FileAccess.ReadWrite))
            {
                var workBook   = new XSSFWorkbook(fs);
                var firstSheet = workBook.GetSheetAt(0); // 约定只有第一个工作簿为有效导出源
                SheetInfo = new ExcelSheetInfo(firstSheet);
                var chineseCommentRow = firstSheet.GetRow(readRule.ChineseCommentIndex);
                var englishCommentRow = firstSheet.GetRow(readRule.EnglishCommentIndex);
                var fieldDefineRow    = firstSheet.GetRow(readRule.StrcutDefineIndex);

                //字段数
                var fieldCount = chineseCommentRow.PhysicalNumberOfCells;

                for (var index = 0; index < fieldCount; index++)
                {
                    try
                    {
                        var chineseComment = chineseCommentRow.GetCell(index).ToString();
                        var englishComment = englishCommentRow.GetCell(index).ToString();
                        var fieldDefineStr = fieldDefineRow.GetCell(index).ToString();
                        //字段类型
                        var fieldType = GetFieldDefine(fieldDefineStr);
                        //字段备注
                        var fieldClassDesc = TryGetClassFieldDesc(fieldDefineStr);
                        //分隔符
                        var arraySplit = TryGetArraySplit(fieldDefineStr);

                        var fieldInfo = new ExcelFieldInfo(
                            englishComment,
                            chineseComment,
                            fieldType,
                            arraySplit,
                            index,
                            SheetInfo.EnglishId,
                            fieldClassDesc);
                        SheetInfo.AddFieldInfo(fieldInfo);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"在解析Excel文件{excelFilePath}的第{index}列时发生异常," +
                                            $"异常信息为{e.Message}!");
                    }
                }
            }
        }
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            var codeStr = string.Empty;

            switch (languageType)
            {
            case "Csharp":
                codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
                          $"= cells[{fieldInfo.Index}].ToBool();";
                break;

            case "TypeScript":
                break;
            }

            return(codeStr);
        }
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            var codeStr = string.Empty;

            //if (languageType == YuExcelConstant.CsLanguageType)
            //{
            //    codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
            //              $"= cells[{fieldInfo.Index}].Split('{fieldInfo.ArraySplit}').ToList();";
            //}

            //if (languageType == YuExcelConstant.TsLanguageType)
            //{
            //    codeStr = $"entity.{fieldInfo.EnglishName} " +
            //              $"= cells[{fieldInfo.Index}].split('_');";
            //}

            return(codeStr);
        }
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            var codeStr = string.Empty;

            switch (languageType)
            {
            case "Csharp":
                codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
                          $"= Convert.ToInt64(cells[{fieldInfo.Index}]);";
                break;

            case "TypeScript":
                codeStr = $"entity.{fieldInfo.EnglishName} " +
                          $"= parseLong(cells[{fieldInfo.Index}]);";
                break;
            }

            return(codeStr);
        }
Exemplo n.º 6
0
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            var codeStr = string.Empty;

            switch (languageType)
            {
            case "Csharp":
                codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
                          $"= cells[{fieldInfo.Index}].ToListFloat('{fieldInfo.ArraySplit}');";
                break;

            case "TypeScript":
                codeStr = $"entity.{fieldInfo.EnglishName} " +
                          $"= parseListFloat(cells[{fieldInfo.Index}]);";
                break;
            }

            return(codeStr);
        }
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            var creator = new YuExcelInternalClassScriptCreator(fieldInfo);

            creator.CreateScript();

            var codeStr = string.Empty;

            switch (languageType)
            {
            case "Csharp":
                codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
                          $"= {fieldInfo.ScriptId}.Create(cells[{fieldInfo.Index}]);";
                break;

            case "TypeScript":
                break;
            }

            return(codeStr);
        }
        public string GetCodeStr(string languageType, ExcelFieldInfo fieldInfo)
        {
            // 首先创建或更新枚举脚本。
            //var enumCreator = new ExcelEnumScriptCreator(u3DAppSetting, fieldInfo);
            //enumCreator.CreateScript();

            var codeStr = string.Empty;

            switch (languageType)
            {
            case "Csharp":
                ////codeStr = $"{fieldInfo.EnglishName.ToLower()} " +
                ////          $"= cells[{fieldInfo.Index}].AsEnum<{enumCreator.EnumName}>();";
                break;

            case "TypeScript":
                codeStr = $"entity.{fieldInfo.EnglishName} " +
                          $"= parseInt(cells[{fieldInfo.Index}]);";
                break;
            }

            return(codeStr);
        }
 public YuExcelInternalClassScriptCreator(ExcelFieldInfo fieldInfo)
 {
     FieldInfo   = fieldInfo;
     OperateInfo = new YuExcelClassOperateInfo(fieldInfo.FieldClassDesc);
 }
 public ScriptCreator(ExcelFieldInfo fieldInfo)
 {
     FieldInfo     = fieldInfo;
     SimpleObjInfo = new YuExcelSimpleObjInfo(fieldInfo.FieldClassDesc);
 }
Exemplo n.º 11
0
 public static string GetWithinClassId(ExcelFieldInfo fieldInfo)
 //=> $"{YuU3dAppSettingDati.CurrentActual.LocAppId}_ExcelWithinClass_{fieldInfo.EnglishName}";
 => $"ExcelWithinClass_{fieldInfo.EnglishName}";