Python和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中的R1C1


下一篇:从Python Pyramid项目导出到Excel .xlsx