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
  interactive process for input and output maiya 1 623 Mar-27-2025, 08:40 AM
Last Post: Gribouillis
  Excel password recovery tool for work OTH 6 4,882 Mar-06-2025, 03:49 PM
Last Post: Pedroski55
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 28,274 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  How to write variable in a python file then import it in another python file? tatahuft 4 991 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Getting an error while trying to process data, low memory when memory is not low? bkeith12 0 553 Dec-20-2024, 03:06 PM
Last Post: bkeith12
  How to run shell command, capture the output, then write it into textfile? tatahuft 4 1,001 Dec-20-2024, 02:13 PM
Last Post: Axel_Erfurt
  Write json data to csv Olive 6 1,401 Oct-22-2024, 06:59 AM
Last Post: Olive
  [SOLVED] [Linux] Write file and change owner? Winfried 6 1,615 Oct-17-2024, 01:15 AM
Last Post: Winfried
  python read PDF Statement and write it into excel mg24 1 1,026 Sep-22-2024, 11:42 AM
Last Post: Pedroski55
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,108 Aug-26-2024, 10:14 PM
Last Post: shwfgd

Forum Jump:

User Panel Messages

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