xls to csv script

Post Reply
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

xls to csv script

Post by abonsey »

Does anybody have an example of a xls-to-csv script?
I've never done scripting in Switch and don't know where to start!!

Thanks for any help
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: xls to csv script

Post by loicaigon »

Hello,

As there isn't any Excel connector (might I be wrong?), the only solutions I see are to either use a command line utility :
http://www.maketecheasier.com/convert-x ... mand-line/

or

Use a script element and some os language (VB or APS) to drive excel and get the CSV exported.

FWIW,

Loic
http://www.ozalto.com
BuckXUK
Newbie
Posts: 16
Joined: Thu Mar 01, 2012 8:43 pm

Re: xls to csv script

Post by BuckXUK »

Just as an option I am successfully using a command line tool called xlsx2csv to perform these types of conversions in Switch.

Just Google xlsx2csv.

Hope this helps.
Regards,

William Buckingham
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

Re: xls to csv script

Post by abonsey »

I can get the script to work via a terminal window but not within the command line.
I've set the path to the script, but do I need to enter %1 %2 %3 data as the script is self-contained?
abonsey
Member
Posts: 98
Joined: Fri May 24, 2013 5:10 pm

Re: xls to csv script

Post by abonsey »

Hi,
I ended up using the Execute Command option with a Python script.
Command: /usr/bin/python
Arguments: /Users/admin/Documents/PythonScripts/xls_to_csv.py

The script uses static input and output name (FileA in the example below)

#! /usr/bin/env python

import xlrd
import csv

book = xlrd.open_workbook('/Users/admin/Documents/PythonScripts/FileA.xls')

# Assuming the fist sheet is of interest
sheet = book.sheet_by_index(0)

# Many options here to control how quotes are handled, etc.
csvWriter = csv.writer(open('/Users/admin/Documents/PythonScripts/FileA.csv', 'w'), delimiter=',')

for i in range(sheet.nrows):
csvWriter.writerow(sheet.row_values(i))

How do I change this to work with variable file names instead ie %1 %2?
I've read about it but never got it to work.

Could somebody help me please?
Post Reply