简体   繁体   中英

How to perform excel operation via Python?

I am working on a project and want to write excel and csv files from python 3 on my windows server. Can anyone help if the goal could be achieved from python ? A HOW would be utterly appreciated.

Thanks for your help !

Python has a great built-in module called csv that will help you with the csv files. There are examples here , and the Python documentation is (as always) your first/close-to-best reference.

As for Excel, I wrote some wrappers for the xlrd and xlwt modules and posted them here: Python script to manipulate excel sheets by auto-filling spaces in columns The answer in that question contains examples of how to use the wrappers, and the wrappers themselves are examples of how to cal xlrd and xlwt. The wrappers I wrote assume square tables (possibly with nulls), one table per worksheet. Anything more exotic than that and you're on your own :)

这是一个致力于python / excel互操作的网站

Python has a built-in library called csv . This library can read csv files and convert them to python data structures, and vice versa. An example (from python documentation):

import csv
with open('eggs.csv', 'w', newline='') as csvfile:
    spamwriter = csv.writer(csvfile, delimiter=' ',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
    spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
    spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM