Dilli Dilli - 1 month ago 13
Python Question

xlsxwriter OUTPUT formatting

I have a if else statement. What I'm trying to do is.

I'm looping through and seeing if there's a specific text on something if it does;
add that text in my output in a specific column if it doesn't leave that field null. However it seems to leave all the field null.

This is my code

for items in parseBio1:

if "Snapchat" in items:
worksheet.write_string(row+1,col+13,items)
else:
worksheet.write_string(row,col+13,"None")

if "com" in items:
worksheet.write_string(row+1, col+11, items)
else:
worksheet.write_string(row,col+11,"None")


This is the output I get.

enter image description here

Per requested. Here's the way I'm parsing my input

parseBio1 = parseBio.split('\n')
row+=1

for items in parseBio1:

if "Snapchat" in items:
worksheet.write_string(row+1,col+13,items)
else:
worksheet.write_string(row,col+13,"None")


This is what happens when i get rid of else statement like this:

for items in parseBio1:

digit = items.isdigit()


if "Snapchat" in items:
worksheet.write_string(row+1,col+13,items)

if "com" in items:
worksheet.write_string(row+1, col+11, items)


The output looks messed up and isn't located where it is suppose to be.
In this case. Row 0 item 'snapchat' field is in row 1 for a different user like this
enter image description here

Answer

Here is what I would do:

for items in parseBio1:

        if "Snapchat" in items:
            worksheet.write_string(row, col+13, items)
        if "com" in items:
            worksheet.write_string(row, col+11, items)

        row += 1

In this way if either Snapchat or com in items, it will populate the respective columns.

Comments