2

I'm trying to copy data to an excel file using xlwt in a python code

  worksheet.write(globdat.cycle,1,fint)

globdat.cycle is a count. No problems there since it gets values 1, 2.... n in each iteration.

BUT

'fint' is an array with an unknown number of entries so I cannot exactly give the number of columns.

How can I be able to copy all the values in 'fint' to the excel file ?

dyon
  • 31
  • 1
  • Check [How to create Excel xlsx files from a script?](http://askubuntu.com/questions/457696/how-to-create-excel-xlsx-files-from-a-script). `xlsxwriter` provides a [write_row()](http://xlsxwriter.readthedocs.org/worksheet.html?highlight=write_row#write_row) method allowing arrays values. – Sylvain Pineau May 04 '15 at 14:00
  • 1
    We're sorry, but this site is all about Ubuntu and its official derivatives as posted on https://wiki.ubuntu.com/Releases so pure python programming questions are off-topic here as well. However, on http://stackoverflow.com, a sister site to Ask Ubuntu, they're very good at programming, so you might be better off there. ;-) – Fabby May 05 '15 at 09:58

1 Answers1

2

You need to loop the array and call worksheet.write for each item. You have to specify which row/column you're writing to so we can use the builtin enumerate to count out each item in the array.

You want something like this:

for i, fintitem in enumerate(fint, start=1):
    worksheet.write(globdat.cycle, i, fintitem)
Oli
  • 289,791
  • 117
  • 680
  • 835
  • Hey. Thank you so much for your reply. It worked a treat. But then I had issues with the allocation of cell space. So I changed into xlsx now it just keeps writing on the same row. Overlapping the previous data. – dyon May 05 '15 at 00:58