[PYTHON] Excel tried to summon QR code with black magic

One day

I will be a copy-paste craftsman ╭ (・ ㅂ ・) و ̑̑ Good!

╰ (`• ω •) ╮-= ni <It is troublesome to make various things from the free QR code creation site. I can't create a website that sets parameters and generates a QR code (꒪ ཫ ꒪;)

Prerequisites

Development environment

item version Remarks
Python 3.7.5

Installation package

item version Remarks
pandas --- Used to read an Excel file
xlrd --- Needed to load excel in pandas
PyInstaller --- exe conversion
qrcode --- QR code generation
Pillow --- png image creation

Bulk package installation

Used to align the environment

requirements.txt


altgraph==0.17
colorama==0.4.3
future==0.18.2
numpy==1.19.0
pandas==1.0.5
pefile==2019.4.18
Pillow==7.1.2
pip==19.2.3
PyInstaller==3.6
python-dateutil==2.8.1
pytz==2020.1
pywin32-ctypes==0.2.0
qrcode==6.1
setuptools==41.2.0
six==1.15.0
xlrd==1.2.0

Environment creation

  1. Create virtual environment --Python environment Right click-> Add environment 8dc31f34-e69d-4b6f-96f5-8a301a403dbe-960x299r.png

--Click OK as it is (you can install the package when creating a virtual environment) 9f4c64a4-1908-4713-b45a-d7a1c958e80e-960x633r.png

  1. Add requirements.txt to your project
  2. Right-click on the created virtual environment-> click Install from requirements.txt 31fd5512-c90b-4d64-8557-74f405923245-960x607r.png

Excel data

ab36a8f2-c3ae-4656-b023-4d21fb7b7f3b-960x107r.png

code

  1. Convert cell information to a character string, determine a delimiter, and concatenate
  2. Convert the string to base64
  3. QR code the base64 string

ExcelToQRCode.py


import sys
import os
import pandas as pd
import qrcode
import base64

def main():
	#Command line arguments
	args = sys.argv
	#Do not process if the argument is less than two
	if len(args) < 2:
		exit()

	#Excel file judgment
	split = os.path.splitext(args[1])
	if split[1] != '.xlsx':
		exit()

	#Get the first sheet
	excel_data = pd.read_excel(args[1], sheet_name = 0, encoding='utf-8')

	param_list = []
	for i, row in excel_data.iterrows():
		if i > 0: 
			temp = ""
			for value in row.iloc[2:8]:
				temp += str(value) + '|'
			temp = temp[:-1]
			full_path = os.getcwd() +'\\' + row.iloc[1] + '.png'
			param_list.append((full_path, temp))

	for index in range(len(param_list)):
		image_qr = qrcode.make(base64.b64encode(param_list[index][1].encode('utf-8')))
		image_qr.save(param_list[index][0])

	if len(param_list) < 1:
		print("There was no QR code to create")
	else:
		print("I created a QR code")

if __name__ == '__main__':
	main()

exe conversion

Type the following command to make it an exe The file size of the exe becomes big, but I close my eyes (˘ω˘)

python


pyinstaller hoge.py --onefile --noconsole

How to use

Drag & drop xlsx file to exe

Code to read

Utility.cs


public static class Utility
{
    public static string Base64Decode(string value)
    {
        return System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(value));
    }

    public static List<string> GetQRCordData(string value)
    {
        string data = Utility.Base64Decode(value);
        return new List<string>(data.Split(new[] { "|" }, System.StringSplitOptions.None));
    }
}

Recommended Posts

Excel tried to summon QR code with black magic
Command to generate QR code
Decrypt the QR code with CNN
I tried to get the authentication code of Qiita API with Python.
I tried to implement Autoencoder with TensorFlow
I tried to visualize AutoEncoder with TensorFlow
I tried to get started with Hy
Convert Excel data to JSON with python
I tried to implement CVAE with PyTorch
I tried to solve TSP with QAOA
AtCoder Green tried to solve with Go
I tried to make my own source code compatible with Chainer v2 alpha
I tried to predict next year with AI
I tried to detect Mario with pytorch + yolov3
I tried to implement reading Dataset with PyTorch
I tried to use lightGBM, xgboost with Boruta
I tried to learn logical operations with TF Learn
I tried to move GAN (mnist) with keras
Python beginners tried to code some energy drinks
I tried to save the data with discord
I tried to detect motion quickly with OpenCV
I tried to integrate with Keras in TFv1.1
I tried Flask with Remote-Containers of VS Code
[Python] How to read excel file with pandas
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to detect an object with M2Det!
I tried to automate sushi making with python
I tried to predict Titanic survival with PyCaret
I tried to operate Linux with Discord Bot
I tried to study DP with Fibonacci sequence
I tried to start Jupyter with Amazon lightsail
I tried to judge Tsundere with Naive Bayes
I made a QR code image with CuteR
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to find out how to streamline the work flow with Excel x Python ①
[Note] How to write QR code and description in the same image with python
I tried to find out how to streamline the work flow with Excel x Python ③