生成1列条形码,将条形码图片插入excel
import os from pystrich.code128 import Code128Encoder import polars as pl from PIL import Image import io import openpyxl from openpyxl.utils import get_column_letter def generate_barcode ( value , output_dir ): """生成条形码图片并返回图片对象""" if not os.path.exists(output_dir): os.makedirs(output_dir) filename = f " { output_dir } / { value } .png" encoder = Code128Encoder( str (value)) encoder.save(filename) img = Image.open(filename) img = img.resize(( 200 , 75 )) img_byte_arr = io.BytesIO() img.save(img_byte_arr, format = 'PNG' ) img_byte_arr = img_byte_arr.getvalue() os.remove(filename) return img_byte_arr def create_excel_with_barcodes ( df , barcode_values , output_dir , output_file ): ...