3

I am trying to write a list into a cell using Python XLWT. Is this possible?

I am currently getting an error:

Exception: Unexpected data type <type 'list'>

The code:

    for x in result:
        sheet1.write(row2,0,x[0])
        sheet1.write(row2,1,x[1])

x[1] will be a list.

Thanks!

Emile
  • 3,464
  • 8
  • 46
  • 77
  • 1
    Before asking "Can I do X to an Excel file using module M?", ask yourself "Can I do X to an Excel file using the Excel application?". – John Machin Oct 23 '11 at 04:34

1 Answers1

5

Try converting it to a string first:

for x in result:
    sheet1.write(row2,0,str(x[0]))
    sheet1.write(row2,1,str(x[1]))
TorelTwiddler
  • 5,996
  • 2
  • 32
  • 39
  • Yeah I'm doing that for the time being, but just wondered if there is a better way – Emile Oct 13 '11 at 00:14
  • Other than formatting the list in a different way, or pickling it or something, not sure there's much else you can do. Excel documents don't read Python objects, just strings. – TorelTwiddler Oct 13 '11 at 00:16