Python 和 openpyxl - 更改列宽以适应?

标签 python width openpyxl

假设我有一个工作簿,我想确保所有列都是可读的;我如何根据单元格的文本确定列的宽度,然后更改列的宽度?

最佳答案

您无法真正准确地做到这一点:列宽是使用计算机系统上安装的带有一些填充的字体来计算的。因此,您只能使用最佳猜测。

您可以为列设置 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/

相关文章:

php - Windows 上的多个 Web 开发环境

python - 如何在Python中对大量点进行反向地理编码?

python - Pyramid 中的强制身份验证

css - Body 元素显示在 Content Wrapper 后面,宽度为 100%

python - 使用 Python 或 R 读取动态网页 html

html - 固定布局 + 广泛内容 = 表格?

c - 有没有办法在编译时计算整数类型的宽度?

python - 迭代 Excel 行并根据满足条件删除的最佳方法

python-3.x - 如何使用 Openpyxl 访问 Onedrive 上的 Excel 文件

python - 使用openpyxl用颜色填充单元格?