AutoFit不适用于包装的文字 [英] AutoFit doesn't work with wrapped text

查看:134
本文介绍了AutoFit不适用于包装的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单元格中有一个Chr(10)

I have one Chr(10) in the cell

cell.WrapText = False
cell.EntireRow.AutoFit ' AutoFit works
' ------------ but:
cell.WrapText = True
cell.EntireRow.AutoFit ' AutoFit works only if the cell has less then five lines.

如果我添加一些字符(一行多) - AutoFit不起作用。文本被删除在第一行和最后一行。

ver - 着名的excel 2010

If I add some characters (one line more) - AutoFit doesn't work. Text is cutted on the first and last line.
ver - famous excel 2010

推荐答案

这取决于数据有多大,列的宽度是多少?原因是一行可以展开的最大高度是 409.5(546像素)。如果您手动增加行的高度,您将注意到,在特定高度之后,您将无法增加行的高度。检查是什么高度:)同样的宽度的概念。这适用于行和列。在列的情况下,最大宽度为 254.86(1789像素)

It depends on how big the data is and what is the width of the column. Reason being the max height a row can expand is to 409.5 (546 pixels). If you manually increase the height of the row, you will notice that after a particular height, you will not be able to increase the height of the row. Check what is that height :) Same is the concept with the width. This is applicable to both rows and columns. In case of columns the max width is 254.86 (1789 pixels)

我用此代码进行演示。 / p>

I used this code for demonstration purpose.

Option Explicit

Sub Sample()
    ActiveCell.WrapText = True
    ActiveCell.EntireRow.AutoFit
    MsgBox ActiveCell.RowHeight
End Sub

看到这个截图

这不

行已达到最大值。它不能超越那个。

The row has reach it's maximum. It cannot go beyond that.

处理这个问题的最好方法是增加列的宽度。

The best way to handle this is to increase the width of the column.

FOLLOWUP

它不工作的原因是因为您有多列数据在该行,而您正在尝试设置1单元格的WrapText,因此它不工作。当您有多列数据时,您必须使用 cell.EntireRow.WrapText = True 而不是 ActiveCell.WrapText = True

The reason why it was not working is because you had multiple columns with data in that row and you were trying to just set the WrapText of 1 cell and hence it was not working. When you have multiple columns of data you have to use cell.EntireRow.WrapText = True instead of ActiveCell.WrapText = True

这篇关于AutoFit不适用于包装的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆