I wanted my code to have a button that lets me select the file I wanted to use instead of manually typing the file name in the code. My file is the file1234 as you can see below from my code. I also wanted to use ipywidgets if possible.
from openpyxl import Workbook
wb = Workbook()
with open('file1234.txt', encoding='utf-8') as blah:
row = 1
column = 1
ws = wb.active
lines = [line for line in blah.readlines()
if 'entered the channel' not in line
and 'left the channel' not in line]
for line in lines:
if column == 1:
## split the line and rejoin
value = " ".join(line.strip().split(' ')[2:])
else:
value = line.strip()
ws.cell(row=row, column=column, value=value)
if (column := column + 1) > 3:
row += 1
column = 1
for column_cells in ws.columns:
length = max(len(str(cell.value)) for cell in column_cells)
ws.column_dimensions[column_cells[0].column_letter].width = length
wb.save('txt_toexl.xlsx')