Excel sheetName 过滤特殊字符

        public static string GetSafeSheetName(string sheetName)
        {
            if (string.IsNullOrEmpty(sheetName))
            {
                return " ";
            }
            var sb = new StringBuilder();
            foreach (var c in sheetName)
            {
                switch (c)
                {
                    case '*':
                    case '/':
                    case ':':
                    case '?':
                    case '[':
                    case '\\':
                    case ']':
                        sb.Append(' '); break;
                    default: sb.Append(c); break;
                }
                if (sb.Length >= 31) break;
            }
            if (sb[0] == '\'')
            {
                sb[0] = ' ';
            }
            if (sb[sb.Length - 1] == '\'')
            {
                sb[sb.Length - 1] = ' ';
            }
            return sb.ToString();
        }

 

上一篇:Python 合并多Excel案例


下一篇:【数据分析&数据挖掘】相同数据结构互相填充