1 year ago

#388744

test-img

simplyconfused

Python xlwt - looping through sales (works with csv.writer)

I am trying to transfer my .csv output to .xslx as well but am having a bit of a trouble understanding how to loop through my sales with xlwt. I've read the following tutorials but no help there: https://toricode.com/python-write-excel-file-using-xlwt/ and https://tutorialmeta.com/question/understanding-for-loop-with-xlwt

The way it's done with csv.writer is as follows:

fieldnames = [
        _("Date"),
        _("Type"),
        _("Price")
        _("CustomerFName"),
        _("CustomerLName"),
    ]
   
    writer = csv.writer(output)
    writer.writerow(fieldnames)

    for s in sales:
        for sale in s.sales.all():
            row = [
                s.date,
                sale.type,
                sale.price,
                s.fName,
                s.lName,
            ]
     return output

Any ideas or good examples I could look into?

Thanks in advance.

python

export-to-csv

export-to-excel

xlwt

0 Answers

Your Answer

Accepted video resources