企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` import xlrd from datetime import datetime from xlrd import xldate_as_tuple # 同步订单详细信息 book = xlrd.open_workbook("order.xlsx") sheet = book.sheet_by_name("sheet1") for r in range(1, sheet.nrows): sql = "INSERT INTO tmp_order (`id`, `order_no`, `venue_name`, `user_name`, `student`, `card_no`, `add_time`, `business_type`, `des`, `pay_type`, `phone`, `ticket_num`) VALUES " order_no = sheet.cell(r, 0).value venue_name = sheet.cell(r, 1).value user_name = sheet.cell(r, 2).value student = sheet.cell(r, 3).value card_no = sheet.cell(r, 4).value #日期类型不转float ctype = sheet.cell(r,5).ctype add_time = sheet.cell(r, 5).value if ctype == 3: date = datetime(*xldate_as_tuple(add_time, 0)) add_time = date.strftime('%Y/%m/%d %H:%M:%S') business_type = sheet.cell(r, 6).value des = sheet.cell(r, 7).value pay_type = sheet.cell(r, 12).value phone = sheet.cell(r, 17).value ticket_num = sheet.cell(r, 20).value //其他过滤逻辑 values = "(NULL,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % ( order_no, venue_name, user_name, student, card_no, add_time, business_type, des, pay_type, phone, ticket_num) execute_sql = sql + values # print (execute_sql); # if r==2:quit() with open('tmp_order.sql', mode='a', encoding='utf-8') as filename: filename.write(execute_sql) filename.write('\n') # 换行`