Get_Barcode_Number.py 622 B

12345678910111213141516171819202122232425262728
  1. # python 读写剪切板内容, 先用下行命令安装运行库
  2. # python -m pip install pywin32
  3. import win32clipboard as w
  4. import win32con
  5. import re
  6. def getText():
  7. w.OpenClipboard()
  8. d = w.GetClipboardData(win32con.CF_TEXT)
  9. w.CloseClipboard()
  10. return(d).decode('GBK')
  11. def setText(aString):
  12. w.OpenClipboard()
  13. w.EmptyClipboard()
  14. w.SetClipboardText(aString)
  15. w.CloseClipboard()
  16. text = getText()
  17. # 修改一行 编程提取条码数字
  18. list = re.findall(r"\d{12,14}", text)
  19. if len(list) == 0 :
  20. list = re.findall(r"X00[0-9a-zA-Z]+", text)
  21. text = "\n".join(list)
  22. setText(text)
  23. print(text)