Python Forum
Reading data from excel file –> process it >>then write to another excel output file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading data from excel file –> process it >>then write to another excel output file
#1
Hello dear pythonians ,

I have an excel file which containers qr code each in separate line ( see photo attached)
I need to do some processing to extract the data from these QR codes then write the results in another excel file which container the final data after processing.

I have written most of the code except the final stage( write and append to final excel file) where I got stuck :woozy_face: :cold_sweat: -

Here is the code
import pandas as pd
import openpyxl
import tlv8
import base64
  
#create new excel file with header for final output
df = pd.DataFrame(
                   columns=["Seller Name","Vat Number","Invoice Date","Total Amount","Vat Amount"])
df.to_excel("final.xlsx",index=False)

# load excel containing qr code with its path for reading
wrkbk = openpyxl.load_workbook("G:\\qr.xlsx")
  
sh = wrkbk.active
  
# iterate through QR code excel file to input the data for processing
for row in sh.iter_rows():
    for cell in row:
        base64QR=cell.value
        rawByte = base64.b64decode(base64QR)
        str1 = rawByte.decode('UTF-8')  
        structure1 = {
            1: tlv8.DataType.STRING,
            2: tlv8.DataType.STRING,
            3: tlv8.DataType.STRING,
            4: tlv8.DataType.STRING,
            5: tlv8.DataType.STRING
        }
        final_output = tlv8.decode(rawByte, structure1)
        Data_List = [entry.data for entry in final_output]
        final_list = []
        for ele in Data_List:
                final_list.append(ele.strip())
        print(final_list) # final output is a list 
        # final output looks like below : 
        # ['Arnon Plastic Industries Co. Ltd.', '300498609900003', '2023-02-14', 4600.0, 600.0]
My question is :–

I want to loop over all QR codes and append data in a new excel file which contain the header details I already wrote at the beginning.

Here is an example of QR code for testing :–
ASFBcm5vbiBQbGFzdGljIEluZHVzdHJpZXMgQ28uIEx0ZC4CDzMwMDQ5ODYwOTkwMDAwMwMTMjAyMy0wMi0xNCAxMjo0ODoxMwQHNDYwMC4wMAUGNjAwLjAw

Rgds,
Jenni

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What does .flush do? How can I change this to write to the file? Pedroski55 3 232 Apr-22-2024, 01:15 PM
Last Post: snippsat
  encrypt data in json file help jacksfrustration 1 227 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Can rich.logging output to file? pyfoo 1 274 Mar-21-2024, 10:30 AM
Last Post: pyfoo
  Updating formulas in Excel - best solution MasterOfDestr 4 682 Mar-11-2024, 01:02 PM
Last Post: MasterOfDestr
  Python openyxl not updating Excel file MrBean12 1 342 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Excel from SAP - dealing with formats and VBA MasterOfDestr 7 590 Feb-25-2024, 12:23 PM
Last Post: Pedroski55
  Reading and storing a line of output from pexpect child eagerissac 1 4,275 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Python best library for Excel reports & review of existing code MasterOfDestr 4 678 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
  Copy Paste excel files based on the first letters of the file name Viento 2 454 Feb-07-2024, 12:24 PM
Last Post: Viento
  Last record in file doesn't write to newline gonksoup 3 446 Jan-22-2024, 12:56 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020