Advertisement
1nikitas

Untitled

Mar 13th, 2022
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. import xlsxwriter
  2.  
  3.  
  4. def export_check(text):
  5.     workbook = xlsxwriter.Workbook('res.xlsx')
  6.  
  7.     checks = list(map(lambda x: sorted(x.split('\n')), text.split("---")))
  8.     for i in checks:
  9.         add = {}
  10.         for j in i:
  11.             if j == '':
  12.                 continue
  13.  
  14.             cc = j.split('\t')
  15.             key, val = (cc[0], int(cc[1])), int(cc[2])
  16.  
  17.             if key in add:
  18.                 add[key] += val
  19.             else:
  20.                 add[key] = val
  21.         s1 = add.keys()
  22.         s = []
  23.         for i in s1:
  24.             s.append([i[0], int(add[i]), int(i[1])])
  25.         s.sort()
  26.         f = {}
  27.         for i in s:
  28.             f[(i[0], i[2])] = add[(i[0], i[2])]
  29.             del add[(i[0], i[2])]
  30.         if f:
  31.             worksheet = workbook.add_worksheet()
  32.             for row, (item_price, count) in enumerate(f.items()):
  33.                 worksheet.write(row, 0, item_price[0])
  34.                 worksheet.write(row, 1, float(item_price[1]))
  35.                 worksheet.write(row, 2, float(count))
  36.                 worksheet.write(row, 3, f'=B{row + 1}*C{row + 1}')
  37.  
  38.             row += 1
  39.  
  40.             worksheet.write(row, 0, 'Итого')
  41.             worksheet.write(row, 3, f'=SUM(D1:D{row})')
  42.     workbook.close()
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement