Page 1 of 1
xls to csv script
Posted: Fri Mar 06, 2015 10:29 am
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
Re: xls to csv script
Posted: Fri Mar 06, 2015 10:42 am
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
Re: xls to csv script
Posted: Mon Mar 09, 2015 3:51 pm
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.
Re: xls to csv script
Posted: Tue Mar 10, 2015 4:37 pm
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?
Re: xls to csv script
Posted: Fri Mar 13, 2015 12:55 pm
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?