2

I'd like to use in2csv to convert excel files into csv in my python code, but without running it as a separate process using exec. Instead, I'd like to directly import the function and use it, like in2csv("input.xls", "output.csv"), or still better, get directly the structure of the file in python without using the csv reader out the output file.

Is it possible?

Thank you!

1 Answer 1

2

I also had the same issue. I looked into the source code of in2csv and found it internally uses agate and agateexcel. I directly used agate and implemented the following way

For xls file

import agate
import agateexcel

table = agate.Table.from_xls('input.xls', sheet='sheet')

table.to_csv('output.csv')

For xlsx file

import agate
import agateexcel

table = agate.Table.from_xlsx('input.xlsx', sheet='sheet')

table.to_csv('output.csv')

https://github.com/wireservice/csvkit/blob/master/csvkit/utilities/in2csv.py

Sign up to request clarification or add additional context in comments.

3 Comments

How to specify delimiter?
In csv file while saving ?
yes. sep and delimiter keyword are not accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.