Ejemplo n.º 1
0
    /// <summary>
    /// 缓存单元格数据
    /// </summary>
    public void CacheAllCellValue(SheetData sheet)
    {
        for (int i = 0; i < sheet.Heads.Count; i++)
        {
            HeadWrapper head = sheet.Heads[i];

            // 如果是备注列
            if (head.IsNotes)
            {
                _cellValues.Add(head.CellNum, string.Empty);
                continue;
            }

            // 获取单元格字符串
            ICell  cell  = Row.GetCell(head.CellNum);
            string value = sheet.GetCellValue(cell);

            // 检测数值单元格是否为空值
            if (string.IsNullOrEmpty(value))
            {
                if (head.Type == "int" || head.Type == "long" || head.Type == "float" || head.Type == "double" ||
                    head.Type == "enum" || head.Type == "bool")
                {
                    // 如果开启了自动补全功能
                    if (SettingConfig.Instance.EnableAutoCompleteCell)
                    {
                        value = SettingConfig.Instance.AutoCompleteCellContent;
                    }
                    else
                    {
                        throw new Exception($"数值单元格不能为空,请检查{head.Name}列");
                    }
                }
            }

            _cellValues.Add(head.CellNum, value);
        }
    }