I'm trying to set the dimensions (height & width) of 100 × 100 cells in an already existing Excel workbook but it fails to set the width of columns to the correct value (though row heights are set to correct values). I'm trying to set the column width to 10 but after opening the actual Excel file, the column widths turn out to be 9.29. What am I doing wrong?
from os import name
import openpyxl
from openpyxl.descriptors.base import DateTime
from openpyxl.utils import get_column_letter
import datetime
def format_wb(wb):
for ws in wb.sheetnames:
for i in range(1, 101):
wb[ws].column_dimensions[get_column_letter(i)].width = 10
wb[ws].row_dimensions[i].height = 20
return wb
def main():
file_name = "test"
wb = openpyxl.load_workbook(f"{file_name}.xlsx")
wb = format_wb(wb)
wb.save(f"{file_name}.xlsx")
if __name__ == "__main__":
main()