'Excel to XML convertor || TypeError: '<' not supported between instances of 'NoneType' and 'int' || Python
I am trying to write a Code that converts Excel data into XML files via Python and this error keeps popping up on line 80.
TypeError: '<' not supported between instances of 'NoneType' and 'int'
I did look similar answers to this error here, on StackOverflow, but they also don't seem to work.
from openpyxl import load_workbook
from yattag import Doc, indent
# Load our Excel File
wb = load_workbook("testQWERTY.xlsx")
# Getting an object of active sheet 1
ws = wb.worksheets[0]
# to get the active work sheet
sh = wb.active
# Returning returns a triplet
doc, tag, text = Doc().tagtext()
xml_header = '<?xml version="1.0" encoding="UTF-8"?>'
# Appends the String to document
doc.asis(xml_header)
with tag('ENVELOPE'):
with tag('HEADER'):
text('Import Tally')
with tag('BODY'):
with tag('IMPORTDATA'):
with tag('REQUESTDESC'):
with tag('REPORTNAME'):
text('All Masters')
with tag('STATICVARIABLES'):
with tag('SVCURRENTCOMPANY'):
text('NIKASH')
with tag('REQUESTDATA'):
for row in ws.iter_rows(min_row=2, max_row=sh.max_row, min_col=1, max_col=sh.max_column):
row = [cell.value for cell in row]
with tag("TALLYMESSAGE", 'xmlns:UDF="TallyUDF"'):
with tag("VOUCHER", 'ACTION="Create"', 'VCHTYPE="{}"'.format(row[1])):
with tag("VOUCHERTYPENAME"):
if (row[1] == None):
text()
else:
text(row[1])
with tag("DATE"):
if (row[0] == None):
text()
else:
text(row[0])
with tag("VOUCHERNUMBER"):
if (row[3] == None):
text()
else:
text(row[3])
with tag("PARTYLEDGERNAME"):
if (row[4] == None):
text()
else:
text(row[4])
with tag("NARRATION"):
if (row[2] == None):
text()
else:
text(row[2])
with tag("EFFECTIVEDATE"):
if (row[0] == None):
text()
else:
text(row[0])
# All Ledger Entries from here
with tag("ALLLEDGERENTRIES.LIST"):
#Data 1
with tag("LEDGERNAME"):
if (row[4] == None):
text()
else:
text(row[4])
with tag("REMOVEZEROENTRIES"):
text("NO")
with tag("LEDGERFROMITEM"):
text("NO")
with tag("ISDEEMEDPOSITIVE"):
if (row[5] < 0):
text("YES")
else:
text("NO")
with tag("AMOUNT"):
if (row[5] == None):
text()
else:
text(row[5])
#Data 2
with tag("LEDGERNAME"):
if (row[8] == None):
text()
else:
text(row[8])
with tag("REMOVEZEROENTRIES"):
text("NO")
with tag("LEDGERFROMITEM"):
text("NO")
with tag("ISDEEMEDPOSITIVE"):
if (row[9] < 0):
text("YES")
else:
text("NO")
with tag("AMOUNT"):
if (row[9] == None):
text()
else:
text(row[9])
#Data 3 to 10
for x in range(10, 26, 2):
if (row[x] != None):
with tag("LEDGERNAME"):
if (row[x] == None):
text()
else:
text(row[x])
with tag("REMOVEZEROENTRIES"):
text("NO")
with tag("LEDGERFROMITEM"):
text("NO")
with tag("ISDEEMEDPOSITIVE"):
if (row[x+1] < 0):
text("YES")
else:
text("NO")
with tag("AMOUNT"):
if (row[x+1] == None):
text()
else:
text(row[x+1])
result = indent(
doc.getvalue(),
)
with open("output.xml", "w") as f:
f.write(result)
The other big issue is, this error only pops up when I have converted my Python Code to a .exe file and then run it. Running the Code from VSCode itself doesn't give any error.
The specific part of the code that is creating issues is this-
with tag("ISDEEMEDPOSITIVE"):
if (row[5] < 0):
text("YES")
else:
text("NO")
This part gets repeated a few more times too...
Requesting any user to please share an alternate code for doing the exact same since the other answers discussed on the site for handling the above error seem to make trouble too.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
