有没有一种方法可以设置行高以匹配换行的文本高度? [英] Is there a way to set row height to match wrapped text height?

查看:82
本文介绍了有没有一种方法可以设置行高以匹配换行的文本高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到有一种方法可以使用autoResizeColumn()自动设置列宽,但似乎没有一种类似的方法可以自动设置行高以匹配setWrap()文本显示的高度.我该如何编写脚本以确定给定包装单元的高度,以便可以将其与setRowHeight()一起使用?有没有办法查看单元格的字符串值是如何包装的?我相信getRowHeight()返回的是设置"高度,而不是显示的高度.

I note there's a way to automatically set column width with autoResizeColumn() but there doesn't appear to be a comparable way to automatically set row height to match the height displayed by setWrap()'d text. How would I script this to determine the height of a given wrapped cell so that I can use it with setRowHeight()? Is there a way to see how the string value of a cell wraps? I believe getRowHeight() returns the "set" height, not the displayed height.

我正在尝试为Excel做与此类似的事情: http://excelribbon.tips. net/T010735_Automatic_Row_Height_for_Wrapped_Text.html

I'm trying to do something comparable to this for Excel: http://excelribbon.tips.net/T010735_Automatic_Row_Height_for_Wrapped_Text.html

实际上,当工作表作为Excel导出时,问题就很明显.

In fact, the problem manifests itself when sheets are exported as Excel.

推荐答案

这确实是导出转换中的错误,而不是脚本中不应包含的错误.也就是说,有可能通过查看行的内容,字体大小和列宽以及换行策略来近似确定行的高度.不会给您确切的价格,但应该能够足够接近.如果保守地调整大小,最糟糕的情况是您可能会有多余的空白行.

This is really a bug in the export conversion, not something that should be none in a script. That said, it might be possible to approximately determine the row hight by looking at the contents of the row, the font size, and column width, and wrap policy. Won't give you an exact hight, but should be able to get close enough. If you size conservatively, worse case is you may have an extra line of empty space.

这样做可能需要解决一些潜在问题(请参见

There are some potential issues that you might have to work around in doing so (see https://code.google.com/p/google-apps-script-issues/issues/detail?id=4187)

这篇关于有没有一种方法可以设置行高以匹配换行的文本高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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