假设我有一个工作簿,我想确保所有列都是可读的;我如何根据单元格的文本确定列的宽度,然后更改列的宽度?
最佳答案
您无法真正准确地做到这一点:列宽是使用计算机系统上安装的带有一些填充的字体来计算的。因此,您只能使用最佳猜测。
您可以为列设置 bestFit
属性,但这通常不会达到您的预期。
来自specification § 18.3.1.13:
'Best fit' is set to true under these conditions:
- The column width has never been manually set by the user, AND
- The column width is not the default width
- 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should automatically resize to display the number.
关于Python 和 openpyxl - 更改列宽以适应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34033988/