Determining if Excel cell content exceeds default size in Python -
we have scripts write data excel , automatically create pdf report excel file. on occasions, due length of cell, contents cut off seen below.
i'm trying write code adjust cell height after data written excel before pdf created. have python script word wrap, double height, , center vertical alignment provided specify row number (i.e. 10 & 11)
from win32com.client import dispatch excel = dispatch('excel.application') def main(): celladjust() def celladjust(): affected_rows = [10,11] no_of_sheets = excel.sheets.count each_sheet in range(no_of_sheets): row in affected_rows: excel.worksheets(each_sheet+1).rows(row).verticalalignment = 2 excel.worksheets(each_sheet+1).rows(row).wraptext = true excel.worksheets(each_sheet+1).rows(row).rowheight = 31.5 if __name__ == '__main__': main()
i don't want rows because ruins resulting appearance of remaining fields. there way determine if cell's content beyond default width, , if apply function? or there better way automate this?
i use cell object's value method grab value of cell, check width. if it's wide displayed, call celladjust function. have play around width bit find optimal number use.
Comments
Post a Comment