authcodereport.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import os
  2. import xml.etree.ElementTree as ET
  3. import xlwt
  4. # from xlwt import Workbook, XFStyle, Borders, Pattern, Font
  5. import datetime
  6. import time
  7. import xlsxwriter
  8. import sys
  9. import socket
  10. # python3
  11. import configparser
  12. def app_path():
  13. """Returns the base application path."""
  14. if hasattr(sys, 'frozen'):
  15. # Handles PyInstaller
  16. return os.path.dirname(sys.executable) #使用pyinstaller打包后的exe目录
  17. return os.path.dirname(__file__) #没打包前的py目录
  18. current_directory = os.path.dirname(os.path.abspath(__file__))
  19. #tree = ET.parse(current_directory + '\\xml\\AuthCodeReport.xml')
  20. tree = ET.parse(app_path() + '\\xml\\AuthCodeReport.xml')
  21. root = tree.getroot()
  22. #fn = current_directory+ '\\report\\授权码数据记录表' + '.xlsx'
  23. fn = app_path() + '\\report\\授权码数据记录表' + '.xlsx'
  24. workbook = xlsxwriter.Workbook(fn)
  25. #=========样式===============
  26. formatValue = workbook.add_format()
  27. formatValue.set_align('center')
  28. formatValue.set_font_name('等线')
  29. formatValueHead = workbook.add_format()
  30. formatValueHead.set_bold()
  31. formatValueHead.set_font_name('等线')
  32. formatHead = workbook.add_format()
  33. formatHead.set_font_size(20)
  34. formatHead.set_bold()
  35. formatHead.set_font_name('等线')
  36. #===============================
  37. sheetAuth = workbook.add_worksheet('授权码报表')
  38. sheetAuth.write(0, 0, "授权码数据记录表",formatHead)
  39. formatValueHead.set_align('center')
  40. sheetAuth.write(2, 0, '时间',formatValueHead)
  41. sheetAuth.write(2, 1, '用户',formatValueHead)
  42. sheetAuth.write(2, 2, '油站名称',formatValueHead)
  43. sheetAuth.write(2, 3, '油机机型',formatValueHead)
  44. sheetAuth.write(2, 4, '油机ID',formatValueHead)
  45. sheetAuth.write(2, 5, '功能码',formatValueHead)
  46. sheetAuth.write(2, 6, '授权码',formatValueHead)
  47. sheetAuth.write(2, 7, '授权码计数',formatValueHead)
  48. sheetAuth.write(2, 8, '油机类型',formatValueHead)
  49. sheetAuth.set_column('A:A', len('2019-00-00 00:00:00') + 1)
  50. # sheetAuth.set_column('D:D', len('111111111111AAAB') + 1)
  51. # sheetAuth.set_column('E:E', len('111111111111AAAB') + 1)
  52. # sheetAuth.set_column('F:F', len('111111111111AAAB') + 1)
  53. sheetAuth.set_column('B:I', len('111111111111AAAB') + 1)
  54. sheetAuth.set_column('E:E',20 + 1)
  55. sheetAuth.set_column(13, 13, None, None, {'hidden': 1})
  56. for index,authvalue in enumerate(root):
  57. createTime = authvalue.find('createTime').text
  58. user = authvalue.find('user').text
  59. gasStation = authvalue.find('gasStation').text
  60. cpuID = authvalue.find('cpuID').text
  61. functionCode = authvalue.find('functionCode').text
  62. AuthCode = authvalue.find('AuthCode').text
  63. machineType = authvalue.find('machineType').text
  64. authCodeCount = authvalue.find('authCodeCount').text
  65. type = authvalue.find('type').text
  66. tmpformat = formatValue
  67. #===time===
  68. date_time = datetime.datetime.strptime(createTime, '%Y%m%d%H%M%S')
  69. sheetAuth.write(index + 3, 0, date_time.strftime('%Y-%m-%d %H:%M:%S'),tmpformat)
  70. #===========
  71. sheetAuth.write(index + 3, 1, user, tmpformat)
  72. sheetAuth.write(index + 3, 2, gasStation, tmpformat)
  73. sheetAuth.write(index + 3, 3, machineType, tmpformat)
  74. sheetAuth.write(index + 3, 4, cpuID, tmpformat)
  75. sheetAuth.write(index + 3, 5, functionCode, tmpformat)
  76. sheetAuth.write(index + 3, 6, AuthCode, tmpformat)
  77. sheetAuth.write(index + 3, 7, authCodeCount, tmpformat)
  78. sheetAuth.write(index + 3, 8, type, tmpformat)
  79. workbook.close()