Is there a way to derive the result by loading Excel files in different paths using pyinstaller?

Asked 2 years ago, Updated 2 years ago, 166 views

# read file
filename = r"C:\Users\File 1.xlsx"
book = openpyxl.load_workbook(filename)

# sheet extraction
sheet = book.worksheets[0]

# convert read file list
data = []
for row in sheet.rows:
    data.append([
        row[0].value,
        ' ',
        row[3].value,
        row[4].value,
        row[5].value,
        row[6].value, 
        row[7].value,
        row[8].value,
 ])

data = data[1:]

# Extract load file
wb = load_workbook (r"C:\Users\File 2.xlsx")
ws = wb.active

# Excel Input Function
for n, datalist in enumerate(data, 3): 
    for n2, i in enumerate(datalist, 1): 
        cell = ws.cell(row = n, column = n2).value = i


# Insert Content
wb.save ("result file.xlsx")
wb.close()

I wrote a code that reads Excel file 1 and enters the contents in Excel file 2 as Excel file 2.

You want to create an executable file using pyinstaller.

Therefore, when I run the executable file, I want to enter other files in the "File 1" and "File 2" specified above to derive the results, so how should I fill them out?

python excel pyinstaller openpyxl

2022-09-30 01:00

2 Answers

Create a simple Windows program.

I recommend psimplegui.

Find out about Gooey, too.


2022-09-30 01:00

I don't know if it's what you want, but to make it simple, you can create a json file that can be modified in the same directory and modify the json file to produce different results. Below, you can create a data.json file in the same directory and specify the file path and name in it, but you can modify it. If you want to select a file using Windows' file search function, you need to use the Windows GUI library as mentioned above.

data.json file

{"files":
    {
        "readfile":r"C:\Users\File 1.xlsx",
        "writefile":r"C:\Users\File 2.xlsx"
    }
}
import json

jsonfile = "data.json"
with open(jsonfile) as f:
    data = json.loads(f.read())

# read file
filename = data["files"]["readfile"]
book = openpyxl.load_workbook(filename)
...
...
...
# Extract load file
wb = load_workbook(data["files"]["writefile"])
ws = wb.active
...
...
...




2022-09-30 01:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.