Hello, a very fresh beginner here - I’m trying to help my wife with an automation task. I need to write a Python code, which I’d use for a Macro in Excel to export certain fields from a spreadsheet and import them into a new .txt file with a certain view.
This is my code so far:
from openpyxl import load_workbook
data_file_path = '/data/new_export.xlsx'
wb = load_workbook(data_file_path)
ws = wb['Sheet1']
row = list(ws.rows)
column = list(ws.columns)
output_file = open ('/data/output.txt', 'w')
for i in range (1, ws.max_row + 1):
iban_code = ws.cell(row=i, column=1).value
company = ws.cell(row=i, column=2).value
iban_number = ws.cell(row=i, column=3).value
bic = ws.cell(row=i, column=4).value
currency = ws.cell(row=i, column=5).value
amount = ws.cell(row=i, column=6).value
inv_number = ws.cell(row=i, column=7).value
for j in range (1, ws.max_column + 1):
output_file.write(???????)
output_file.close()
What do I need to write in the output brackets, so that I can have an output in the .txt file like this (for every row in the Excel file):
iban_code || company || iban_number || bic || currency || amount || inv_number
iban_code || company || iban_number || bic || currency || amount || inv_number
iban_code || company || iban_number || bic || currency || amount || inv_number
etc.