鍓嶈█鍓嶆鏃堕棿鍥犱负闇€瑕佸鐞嗗緢澶氶獙鏀跺崟锛岄兘鏄畝鍗曠殑澶嶅埗绮樿创鏇挎崲宸ヤ綔锛屾墍浠ユ兂鍒颁簡鐢╬ython鏉ュ鐞嗐€傛帴涓嬫潵杩涘叆姝i~鎴戜娇鐢ㄥ紑鍙戠幆澧僷ython3.6openpyxl3.1.1docx0.2.4瀹炵幇闇€姹傘€傝繖鏄叕鍙稿钩鍙板鍑虹殑璁㈠崟鏄庣粏excel鏂囦欢銆傝繖鏄叕鍙哥殑楠屾敹琛ㄦā鏉裤€傛垜杩欓噷鐨勮姹傛槸鎶奅xcel鏂囦欢涓殑璁㈠崟鍙枫€佽鍗曞叕鍙搞€佸寘瑁广€佹暟閲忓姞涓婃ā鏉跨殑璁㈠崟鍙枫€佺敳鏂广€侀獙鏀舵祴璇曞唴瀹广€傜畝鍗曟潵璇村氨鏄€氳繃python鑴氭湰鍒嗗埆娣诲姞excel鏂囦欢鐨勮鍗曞彿銆佽鍗曞叕鍙搞€佸寘瑁广€佹暟閲忋€傛浛鎹ord鏂囦欢涓殑OrderID銆丆ompany銆丳ackage銆丵uantity瀹炵幇浠g爜銆傛寚瀹氶渶姹傚悗锛岀洿鎺ュ鍏ヤ唬鐮乮mportopenpyxlimportdocximportdatetimedefget_excel_data():#鎵撳紑Excel鏂囦欢wb=openpyxl.load_workbook('orderdetails.xlsx')ws=wb['Sheet1']#鑾峰彇鍗曞厓鏍煎簭鍒楀彿inws['A']:Number.append(cell.value)#鑾峰彇cell鐨勮鍗曞彿inws['C']:OrderID.append(cell.value)#OrderID.pop(0)#鑾峰彇鏁伴噺forcellinws['F']:Quantity.append(cell.value)#鑾峰彇鍏徃鍚嶇Оforcellinws['B']:Company.append(cell.value)#鑾峰彇璁㈠崟鍖呰9forcellinws['D']:Package.append(cell.value)#鏇挎崲word鏂囨。鍐呭foriinrange(len(Number)):#鎵撳紑word鏂囨。new_doc=docx.Document('Deliveryacceptanceform.docx')forpinnew_doc.paragraphs锛歠orrinp.runs:#print(r.text)if'OrderID'inr.text:#鏇挎崲璁㈠崟鍙穒tem=OrderID[i]r.font.underline=Truer.text=r.text.replace('OrderID',item)print('OrderID'+'Changeto'+str(item))if'Quantity'inr.text:#replacequantityitem=Quantity[i]r.font.underline=Truer.text=r.text.replace('Quantity',str(item))print('Quantity'+'changeto'+str(item))if'Company'inr.text:#鏇挎崲鍏徃鍚嶇Оitem=Company[i]r.font.underline=Truer.text=r.text.replace('Company',str(item))print('Company'+'changeto'+str(item))if'Package'inr.text:#鏇挎崲璁㈠崟鍖卛tem=Package[i]r.font.underline=Truer.text=r.text.replace('Package',str(item))print('Package'+'Changeto'+str(item))#鏇挎崲鏃ユ湡#杩欓噷锛屽洜涓哄彲浠ョ洿鎺ユ敼妯℃澘锛屾墍鏈夋敞閲婇兘娉ㄩ噴鎺変簡锛岄渶瑕佹墦寮€瀹?if'Yy'inp.text:#p.text=p.text.replace('Yy',str(year))#if'Mm'inp.text:#p.text=p.text.replace('Mm',str(month))#if'Dd'inp.text:#p.text=p.text.replace('Dd',str(day))#淇濆瓨鏂版枃妗?鏂囦欢鍛藉悕鏍煎紡锛氫氦璐ч獙鏀跺崟-鍏徃鍚嶇О鏃堕棿搴忓彿.docxnew_doc.save('浜よ揣楠屾敹鍗?'+str(鍏徃[i])+str(骞?+str(鏈?+str(鏃?+'-'+str(Number[i])+'.docx')if__name__=="__main__":Number=[]OrderID=[]Quantity=[]Company=[]Package=[]now=datetime.datetime.now()year=now.strftime("%Y")month=now.strftime("%m")day=now.strftime("%d")get_excel_data()杩愯鏁堟灉缁堢锛氭枃浠跺す淇濆瓨鏂囦欢锛氭敞鎰忥細杩欓噷鎴戠湅鍒颁簡涓轰簡鏂逛究鍜屾洿鐩磋鐨勬晥鏋滐紝鏇挎崲浜咵xcel鏂囦欢鐨勬爣棰樻爮銆傚鏋滈渶瑕侊紝鍙互浣跨敤OrderID.pop(0)鍒犻櫎琛ㄥご鍒楀弬鏁帮紝鐒跺悗f鎴栬€呭惊鐜鏁板彲浠ュ噺灏戜竴涓€俧oriinrange(len(Number)-1):鏇挎崲鍚庣殑word鏂囦欢锛氫互涓婂氨鏄暣涓渶姹傜殑瀹炵幇杩囩▼銆傚笇鏈涘澶у鏈夋墍甯姪銆備粖澶╂槸杩欐牱鐨剘鍐嶈馃憢
