Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with Null values #67

Open
klayala opened this issue Oct 17, 2020 · 0 comments
Open

Dealing with Null values #67

klayala opened this issue Oct 17, 2020 · 0 comments

Comments

@klayala
Copy link

klayala commented Oct 17, 2020

Hi.

I am a beginner using mostly python. I am currently trying to incorporate yattag. Currently I am using python to read in an excel file, however there are columns that do have null values and that is normal, because there should be missing values when other columns are not null.

Ideally, I would like for yattag if it sees that a value is NULL to output as
xsi:nil.

here is the code template I am using

`from openpyxl import load_workbook
from yattag import Doc, indent
wb = load_workbook("NY_baby_names.xlsx")
ws = wb.worksheets[0]

Create Yattag doc, tag and text objects

doc, tag, text = Doc().tagtext()
xml_header = ''
xml_schema = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema>'
doc.asis(xml_header)
doc.asis(xml_schema)
with tag('Babies'):
# Use ws.max_row for all rows
for row in ws.iter_rows(min_row=2, max_row=100, min_col=1, max_col=5):
row = [cell.value for cell in row]
with tag("Baby"):
with tag("Name"):
text(row[2])
with tag("Gender"):
text(row[1])
with tag("year"):
text(row[0])
with tag("count"):
text(row[3])
with tag("rank"):
text(row[4])
result = indent(
doc.getvalue(),
indentation = ' ',
indent_text = True
)
with open("baby_names.xml", "w") as f:
f.write(result)`

Would this be possible? I would want for every row to print out in the xml form with all columns included, as opposed to not showing that column if it is null for that row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant