1

I'm still learning with this technology. May I know how to put all values in one column using python and xlsx writer?

Ex.

my_dict = {
'Bob': ['eating', 'watching', 'drinking'], 
'Ann': ['shopping', 'eating', 'drawing'], 
'May': ['riding', 'singing', 'dancing']
}

What I did was putting it in another column.

col_num = 0
row_num = 7
        
col_num = 0
row_num = 7
        
for key, value in my_dict.items():
    worksheet.write_column(row_num, col_num, key)
    worksheet.write_column(row_num + 1, col_num + 1, value)
    row_num += 1

May I know how can I achieve this kind of format? Hoping to get your opinions and suggestions. Thank you

Table

2 Answers 2

2

Use write for the key and write_column for value.

Also, increment the row number by the length of value.

col_num = 0
row_num = 7
        
for key, value in my_dict.items():
    worksheet.write(row_num, col_num, key)
    worksheet.write_column(row_num,  col_num + 1, value)
    row_num += len(value)

workbook.close()
Sign up to request clarification or add additional context in comments.

Comments

1

I got it now. This is what I did:

row_num = 7
        
for key, value in my_dict.items():
    col_num = 0
    worksheet.write(row_num, col_num, key)
    for i in value:
        col_num = 1
        worksheet.write(row_num, col_num, i)
        row_num += 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.