Fix code to set default font size = 10 : from openpyxl import Workbook from…
- User
Fix code to set default font size = 10 : from openpyxl import Workbook from openpyxl.styles import Alignment, Font, PatternFill from openpyxl.utils import get_column_letter
def fill_sheet(sheet, sites): """ Fill the excel sheet with missed cells.
codeArgs: sheet: openpyxl sheet object sites: list """ if len(sites) == 0: return columns = [ 'Region', 'ENM', 'ERBS_Name', 'ID', 'eNBId', 'Vlan', 'VlanRef', 'ExtEnodeB VlanRef', 'EranLink', 'PTP Time Sync', 'Elastic Ran LKF', 'Elastic Ran Feature', 'BBU', 'Port Bitrate', '10G LKF', '10G Feature', 'EUtranCells', 'Eran EUtranCells', ] row = 1 for col in columns: cell = sheet.cell(row=row, column=columns.index(col) + 1) cell.value = col row = 2 for site in sites: for col, cell_val in site.items(): col_index = columns.index(col) +1 cell = sheet.cell(row=row, column=col_index) cell.value = str(cell_val) if col in ['ExtEnodeB VlanRef', 'EranLink', 'EUtranCells', 'Eran EUtranCells']: cell.alignment = Alignment(wrap_text=True) row += 1Autofit columns except for specific columns
code - Assistant
To set the default font size to 10, you need to update the following line of code:
pythonfont = Font(size=10)Replace it with:
pythonfont = Font(size=10, name='Arial', bold=False, italic=False, vertAlign=None, underline='none', strike=False)The updated code sets the font size to 10 and also sets other font attributes to their default values.
- User
line 60, in fill_sheet column_cells.font = font AttributeError: 'tuple' object has no attribute 'font'
- Assistant
The error
"AttributeError: 'tuple' object has no attribute 'font'"occurs because you are trying to assign the font to a tuple instead of a cell object.To fix this issue, you need to loop over the
column_cellsand assign the font to individual cells. Here's the corrected code:python - User
- Assistant