parser_packing.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. '''
  2. Created on Mar 11, 2020 @author: Levi
  3. '''
  4. from parser_intrastat import * # @UnusedWildImport @UnresolvedImport
  5. def parse_packing(articles, export, partners):
  6. ib = xl.load_workbook(articles)
  7. isheet = ib.worksheets[0]
  8. cb = xl.load_workbook(export)
  9. csheet = cb.worksheets[0]
  10. pb = xl.load_workbook(partners)
  11. psheet = pb.worksheets[0]
  12. pack_book = xl.Workbook()
  13. pack_book.create_sheet('packing', 0)
  14. pack_sheet = pack_book.worksheets[0]
  15. header_create(pack_sheet)
  16. for n, p in enumerate(csheet.iter_rows(min_row=2, max_col=14, max_row=csheet.max_row - 1)):
  17. pack_sheet[f'A{n+2}'] = p[4].value # noqa E:226
  18. pack_sheet[f'B{n+2}'] = p[0].value # noqa E:226
  19. pack_sheet[f'L{n+2}'] = p[9].value # noqa E:226
  20. pack_sheet[f'N{n+2}'] = p[11].value # noqa E:226
  21. pack_sheet[f'O{n+2}'] = p[10].value # noqa E:226
  22. pack_sheet[f'P{n+2}'] = p[12].value # noqa E:226
  23. pack_sheet[f'R{n+2}'] = p[13].value # noqa E:226
  24. for c in psheet.iter_rows(min_row=2, max_col=9, max_row=psheet.max_row):
  25. if pack_sheet[f'B{n+2}'].value == c[1].value: # noqa E:226
  26. pack_sheet[f'C{n+2}'] = c[2].value # noqa E:226
  27. pack_sheet[f'D{n+2}'] = c[3].value # noqa E:226
  28. pack_sheet[f'E{n+2}'] = c[4].value # noqa E:226
  29. pack_sheet[f'F{n+2}'] = c[5].value # noqa E:226
  30. pack_sheet[f'G{n+2}'] = c[6].value # noqa E:226
  31. pack_sheet[f'H{n+2}'] = c[7].value # noqa E:226
  32. pack_sheet[f'I{n+2}'] = c[8].value # noqa E:226
  33. for i in isheet.iter_rows(min_row=2, max_col=10, max_row=isheet.max_row):
  34. if pack_sheet[f'L{n+2}'].value == i[1].value: # noqa E:226
  35. pack_sheet[f'K{n+2}'] = i[3].value # noqa E:226
  36. pack_sheet[f'Q{n+2}'] = i[9].value * pack_sheet[f'O{n+2}'].value # noqa E:226
  37. pack_sheet[f'U{n+2}'] = i[6].value * pack_sheet[f'O{n+2}'].value # noqa E:226
  38. pack_sheet[f'V{n+2}'] = i[7].value * pack_sheet[f'O{n+2}'].value # noqa E:226
  39. format_after(pack_sheet, ref=f'A1:Y{pack_sheet.max_row}') # noqa E:226
  40. pack_book.save('packing.xlsx')
  41. if __name__ == '__main__':
  42. parse_packing('intrastat_art.xlsx', 'Export.xlsx', 'intrastat_part.xlsx')