I'm trying to make a parser in python, and what this will do will convert csv into an excel document (xls), is there a way you can format a csv in a python script to a certain excel layout? I'm finding this very difficult and don't know where to start
-
Have you looked at the csv module? https://docs.python.org/2/library/csv.html – EdgeCaseBerg Aug 06 '15 at 14:19
-
have you seen openpyxl? [There seem to be several libraries already](http://www.python-excel.org/), although I haven't tried them - should make the excel-facing side easier. – Steven Kay Aug 06 '15 at 14:22
-
http://stackoverflow.com/questions/17684610/python-convert-csv-to-xlsx dup – FirebladeDan Aug 06 '15 at 14:28
-
possible duplicate of [Recommend a Python library to read Excel XLS files](http://stackoverflow.com/questions/3504604/recommend-a-python-library-to-read-excel-xls-files) – Tolio Aug 06 '15 at 14:29
2 Answers
Welcome to StackOverflow Shaneyg8! Since this is your first post I figure I'd add a few notes about the site while answering your question.
First off:
Python CSV Module will help you with the CSV part. You can easily read a CSV and perform operations on each row like so:
>>> import csv
>>> with open('eggs.csv', 'rb') as csvfile:
... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
... for row in spamreader:
... #Do Stuff!
Second, check out the excellent resource commented by Steven Kay and choose the one whose documentation makes the most sense to you. I'd probably start with openpyxl since it's recommended by the list. Though choosing the right library will be up to your needs and which formats you plan to support and handle with your program.
Last, when you post on Stack Overflow you should let us know what you've tried so far. Did you google your question first? Did you look up csv/excel libraries before asking? Did you try looking up "python convert csv to xlsx"? These are things that can answer your question faster than any of us can, and once you put in that effort to try, if you find yourself lost or wondering how to use feature X, then come t the site, let us know about your issue, and ask the specific question for clarification.
The more information you give us about what you tried, the more information we can give back to you and future viewers of your question.
In your case, you may want to look at the two questions that are related/similar to your question here:
https://stackoverflow.com/questions/3504604/recommend-a-python-library-to-read-excel-xls-files

- 1
- 1

- 2,761
- 1
- 23
- 39
I believe this is a duplicate of Recommend a Python library to read Excel XLS files, but I will answer to give you the directions.
As commented by @EdgeCaseBerg, you can use CSV File Reading and Writing along with xlrd to achieve what you want.