read data from one file(.xlsx), write into another

1

I'm trying to read all rows and column's data from input.xlsx file , and insert into another file output.xlsx using python script (iterate through for loop).

Problem: Using "for loop" in this script able to read data in each row and column but fails to write into output file (output.xlsx)

Here's the code I used:

    response = requests.get(url, params=params, auth=(username, password))
    with open('/Downloads/input.xlsx', 'wb') as f:
            f.write(response.content)

            workbook = load_workbook("/Downloads")

            # get all worksheets
            all_sheets = workbook.sheetnames

            first_sheet = all_sheets[0]

            # get a worksheet by its name
            worksheet = workbook[first_sheet]
            first_row = True
            for val in worksheet.values:
                if first_row:
                    # skip the first row: header row.
                    first_row = False
                    continue

                workbook = xlsxwriter.Workbook('output.xlsx')

                new_worksheet = workbook.add_worksheet()

                new_worksheet.write('A', val[0])
                new_worksheet.write('B', val[1])
                new_worksheet.write('C', val[2])

                workbook.close()   

The Data in input.xlsx looks like the below:

**Student Name | Course | Rank**
Tony             ECE      4
Bob              CSE.     1
Chris            MECH     7
David            CSE      5
Krishna          CSE      2

itgeek

Posted 2020-02-20T16:36:35.743

Reputation: 11

No answers