How to write data to excel file?

I have some data that I would like to save in an excel file. How to do this in python?

+4
source share
4 answers

There is a great python module called XLWT . I would recommend using this ... it writes native Excel files instead of CSV. Supports formulas, etc.

Documentation (borrowed from Mark)

+11
source

I will answer a slightly different question: "How can I write data so that Excel can read it?"

Use the csv module to write your data as a CSV file, and then open it in Excel.

 import csv csvout = csv.writer(open("mydata.csv", "wb")) csvout.writerow(("Country", "Year")) for coutry, year in my_data_iterable(): csvout.writerow((country, year)) 
+5
source

If you need a BIFF8 XLS file, I would use excellent xlwt .

+1
source

if it works on Windows, try creating an instance of EXCEL.APPLICATION through COM

Use Excel Help to reference an object.

That way you can even format data, write formulas, etc.

0
source

Source: https://habr.com/ru/post/1314086/


All Articles