标签:
解决方法:根据单元格内容长度,设置单元格所在行的行高
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);
标签:
原文地址:http://www.cnblogs.com/bluestream/p/4397785.html