解决方法:根据单元格内容长度,设置单元格所在行的行高

      public static float getExcelCellAutoHeight(string strtest, float fontCountInline)
        {
            float defaultRowHeight = 18.00f;//每一行的高度指定
            float defaultCount = 0.00f;
            for (int i = 0; i <strtest.Length; i++)
            {
                float ff = getRegex(strtest.Substring(i, 1));
                defaultCount = defaultCount + ff;
            }
            return ((int)(defaultCount / fontCountInline) + 1) * defaultRowHeight;//计算
        }

 

       public static float getRegex(string charStr)
        {

            if (charStr == " ")
            {
                return 0.5f;
            }
            // 判断是否为字母或字符
            if (Regex.IsMatch(charStr, "^[A-Za-z0-9]+$"))
            {
                return 0.5f;
            }
            // 判断是否为全角
            if (Regex.IsMatch(charStr, "[\u4e00-\u9fa5]+$"))
            {
                return 1.00f;
            }
            //全角符号 及中文
            if (Regex.IsMatch(charStr, "[^x00-xff]"))
            {
                return 1.00f;
            }         
            return 0.5f;

        }

  

 Excel.Range range = ews.get_Range("C" + (12 + indexRow * 10), "H" + 12 + indexRow * 10);
 range.RowHeight = getExcelCellAutoHeight(ProStageName + "", 36f);

 

   

 

相关文章:

  • 2021-05-09
  • 2022-01-20
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2022-02-06
  • 2022-01-24
  • 2022-01-13
  • 2022-01-26
相关资源
相似解决方案