Dear Pro !!
Can you Help me please with this issue ?I wrote the following code to copy all csv to exist excel file
but It Copy just the last record and I can't understand why?
def emptyrow(): # Load the Excel file and select the worksheet workbook = openpyxl.load_workbook('test.xlsx') worksheet = workbook.active # Find the last row with data in the worksheet last_row = worksheet.max_row print(last_row) # Load the CSV file and read the data with open('D:\Downloads\A (2).csv', 'r') as csv_file: csv_reader = csv.reader(csv_file) data = list(csv_reader) #print(data) # Write the CSV data to the worksheet for row in data: for col, value in enumerate(row): worksheet.cell(row=last_row+1, column=col+1, value=value) # Save the changes to the Excel file workbook.save('test.xlsx') emptyrow()Please Advise ?
Larz60+ write Mar-23-2023, 11:47 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.