2

What I need is a command line tool to convert excel and ods spreadsheet files to csv which I can use on a web server (Ubuntu 16.04). I already red this: https://pypi.python.org/pypi/unotools which works fine for the given examples.

And this: http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno-part-1v2 which should do the work I want it to do, but does not in my environment.

My problem I think is in the method Calc.store_to_url:

Line throwing exception

component.store_to_url(url,'FilterName','Text - txt - csv (StarCalc)')

I really would appreciate a hint.

Exception

unotools.unohelper.ErrorCodeIOException: SfxBaseModel::impl_store failed: 0x81a

Full source

import sys
from os.path import basename, join as pathjoin, splitext

from unotools import Socket, connect
from unotools.component.calc import Calc
from unotools.unohelper import convert_path_to_url
from unotools import parse_argument



def get_component(args, context):
    _, ext = splitext(args.file_)
    url = convert_path_to_url(args.file_)
    component = Calc(context, url)
    return component

def convert_csv(args, context):
    component = get_component(args, context)
    url = 'out/result.csv'    
    component.store_to_url(url,'FilterName','Text - txt - csv (StarCalc)')
    component.close(True)


args = parse_argument(sys.argv[1:])
context = connect(Socket(args.host, args.port), option=args.option)

convert_csv(args, context)
dlg_
  • 307
  • 4
  • 11
  • which parameters are you passing to the `convert_csv()`? – Ma0 Mar 10 '17 at 14:59
  • 1
    full command is: python3 convert.py -s localhost -p 2002 -f excel.xlsx (host and port are checked and doing fine) – dlg_ Mar 10 '17 at 15:02
  • This question uses `unotools` rather than straight `pyuno`, so the title and tag are misleading. However the issue is relevant to any code that uses the UNO interface. – Jim K Mar 10 '17 at 17:46

1 Answers1

2

The URL must be in file:// format.

url = convert_path_to_url('out/result.csv')

See the store_to_url example at https://pypi.python.org/pypi/unotools.

EDIT:

To use the absolute path, choose one of these; there is no need to combine them.

url = 'file:///home/me/out/result.csv'
url = convert_path_to_url('/home/me/out/result.csv')

To use the relative path, first verify that the working directory is '/home/me' by calling os.getcwd().

Community
  • 1
  • 1
Jim K
  • 12,824
  • 2
  • 22
  • 51
  • Thanks a lot. That works fine but I had to use absolute path like: convert_path_to_url('file:///home/me/out/result.csv') – dlg_ Mar 14 '17 at 13:23