Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xlwt
- import xml.etree.ElementTree as ET
- import sys
- import xml
- pmtflds = ['PmtType', 'PmtStatus', 'PrcDate']
- flds = ['PmtID', 'Name1', 'ValueDate', 'CurAmt', 'CurCode', 'Error']
- wb = xlwt.Workbook()
- ws = wb.add_sheet('TranACK')
- wrapstyle = xlwt.XFStyle()
- wrapstyle.alignment.wrap = 1
- for (i, n) in enumerate(pmtflds + flds):
- ws.write(0, i, n)
- tree = ET.parse(sys.argv[1])
- root = tree.getroot()
- width = 0
- #ET.dump(root)
- row = 1
- for ack in root:
- for item in ack:
- if item.tag != 'TranACK':
- continue
- for (i, n) in enumerate(pmtflds):
- ws.write(row, i, ack.attrib[n])
- for (fldnum, fld) in enumerate(flds):
- print('searching for {}'.format(fld))
- val = '\n'.join([i.text.strip() for i in item.findall(fld) if i != None])
- if '\n' in val:
- for s in val.split('\n'):
- if len(s) > width:
- width = len(s)
- ws.write(row, fldnum+len(pmtflds), val, wrapstyle)
- else:
- ws.write(row, fldnum+len(pmtflds), val)
- print('')
- row += 1
- ws.col(8).width = width * 256
- wb.save('wfack.xls')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement