Guest User

foo

a guest
Jun 21st, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | Source Code | 0 0
  1. import openpyxl
  2. import re
  3. from datetime import date
  4.  
  5. workbook = openpyxl.Workbook()
  6. today = date.today()
  7. date_stamp = today.strftime("%Y-%m-%d")
  8. filename = f"neue_datei_{date_stamp}.xlsx"
  9. sheet = workbook.active
  10.  
  11. with open('ErrorStack.txt', 'r') as file:
  12. text = file.read()
  13.  
  14. pattern = r"((.*?Name:\s{0,1}(.*?)\s).*?\-{5,})"
  15.  
  16. matches = re.findall(pattern, text, re.DOTALL)
  17.  
  18. for match in matches:
  19. sheet_name = match[2]
  20. sheet = workbook.create_sheet(title=sheet_name)
  21.  
  22. for row in match[0].split('\n'):
  23. sheet.append(row.split(','))
  24.  
  25. workbook.remove(workbook['Sheet'])
  26. workbook.save(filename)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment