Converting specific Excel file tabs to CSV in Python


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting specific Excel file tabs to CSV in Python
# 1  
Old 02-29-2012
Java Converting specific Excel file tabs to CSV in Python

Hi list,

This is probably something really simple, but I am not particularly familiar with Python so I thought I would ask as I know that python has an excel module.

I have an excel document with multiple tabs of data and graphs.
One of the tabs is just data which I require to have dumped to a csv file.
So what I want to do is process the excel document and output the 4th tab of excel data to a raw CSV file.

Does anyone have a recipe for this?

Any help much appreciated..

Thanks,
land
# 2  
Old 02-29-2012
Code:
$ cat a.csv
"One 1","Two 2","Three 3","Four 4"
11,22,33,44
one,two,three,four

$ cat a.py
#! /usr/bin/python

import csv
f=open('a.csv')
r=csv.reader(f)
for row in r:
        print row[2]
f.close()

$ ./a.py
Three 3
33
three

# 3  
Old 02-29-2012
Hi chihung,

Thanks for your reply. However it looks like you are reading from a CSV file.
What I am trying to achieve is open a Microsoft Excel file and export one of the tabs of the MS Excel file to a CSV file.
# 4  
Old 02-29-2012
You can download the Windows version of ActivePython from ActiveState Software - Code to Cloud: Smarter, Safer, Faster | ActiveState. Their python has COM module included so that you can use COM to drive the application via python. See the documentation for details.

I have not try AcitvePython, but tried with ActiveTcl. Good luck.
# 5  
Old 02-29-2012
Thanks chihung, but the MS Excel file is being processed on a Linux server, so this script will require a module to run in Linux.

I'm sure there is an excel module for python to convert MS excel tabs into CSV under Linux. The question is what is the recipe to do this specific task.
# 6  
Old 02-29-2012
I don't think there is an equivalent COM on Linux to process Excel. You may want to explore using OpenOffice on the Linux side to process Excel.
# 7  
Old 02-29-2012
Hi chihung,

I note there is a python module here which is able to process excel.

So back to my initial question to any Python guru's. What would be the recipe for exporting a tab from an MS Excel spreadsheet file to a CSV file.

The reason I must be able to script this is because this process needs to be an automated end-to-end process.

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert excel to csv in python date not display exactly

Hi, Anyone can help I am just converting the excel file to csv using python, I can get the conversion output but the date not display exactly. test.xlsx date format 167 1588 risks/SCS JP CAMPANA & CIE.pdf SCS JP CAMPANA & CIE 2 1 1 0 2015-03-16 16:56:25 167 1146 risks/AirBNB... (1 Reply)
Discussion started by: fspalero
1 Replies

2. Shell Programming and Scripting

Error while Converting Excel to CSV using xls2csv

I am using xls2csv to convert a xls file into a regular .csv file. However, while using the command as xls2csv fromfile.xls > tofile.csv I am getting the following error. fromfile.xls is not OLE file or Error I also tried to specify the comma as delimiter but did not help... xls2csv -c\,... (7 Replies)
Discussion started by: dhruuv369
7 Replies

3. Shell Programming and Scripting

Shell Script for converting file to Excel or CSV

Hi I have a dat file which has "n" number of columns. The file is delimited. The number of columns keep varying as the file is generated out of DB queries. Could you please help me in writing a script which will generate a XLS or CSV file out of the dat file. (5 Replies)
Discussion started by: Vee
5 Replies

4. Shell Programming and Scripting

Converting huge xls(having multiple tabs) to csv

hello I have browsed for the similar requirement i found this https://www.unix.com/shell-programming-scripting/40163-xls-csv-conversion.html but my problem is i have multiple tabs in xls file having same metadata I want to convert it into single csv file any ways to do it pls... (5 Replies)
Discussion started by: joshiamit
5 Replies

5. Shell Programming and Scripting

KSH - Text from input file truncated while converting it to excel

Dear Members, I am using the attached script to convert a input file delimited by '|' to excel. However, while processing the attribute change_reason, the whole content of the text under change_reason is not displayed completely in the cell in excel. It is truncated after only first few words.... (1 Reply)
Discussion started by: Yoodit
1 Replies

6. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

7. Shell Programming and Scripting

converting specific XML file to CSV

Hi, i would convert the following XML file : <?xml version="1.0" encoding="UTF-8" ?> <files xmlns="http://www.lotus.com/dxl/console"> <filedata notesversion="6" odsversion="43" logged="yes" backup="no" id="C12577E6:004B0DA3" iid="C12577E6:004B0DA8" link="1" dboptions="0,524288,0,0"> ... (24 Replies)
Discussion started by: Nicol
24 Replies

8. UNIX for Dummies Questions & Answers

two csv file in an excel file in two tabs

Hi, I was wondering if anybody could help me with this. I have two .csv file that I need to put it in an excel file in two different tabs using Shell Script. Thanks in advance. JP (7 Replies)
Discussion started by: JPalt
7 Replies

9. UNIX for Advanced & Expert Users

Problem in converting password protected excel file to csv file in unix

I need to convert a password protected excel file which will be in UNIX server to a comma separated file. For this I need to open the excel file in UNIX box but the UNIX box doesn't prompt for password instead it is opened in an encrypted manner. I could manually ftp the excel file to local... (2 Replies)
Discussion started by: Devivish
2 Replies

10. Shell Programming and Scripting

Converting tabs in to spaces.

Hi! I'm using SunOS 5.7 w/ Bash 2.01. Currently, I'm working on a script that will make it possible to find textfiles which match certain criteria. While I write this message, I had some brainfarts, found the answer myself :D and the question I had in mind is now no longer the question I... (3 Replies)
Discussion started by: indo1144
3 Replies
Login or Register to Ask a Question

Featured Tech Videos