unotools - 尝试使用 python 将 ods 或 excel 文件转换为 csv
unotools - try to convert ods or excel files to csv using python
我需要一个命令行工具来将 excel 和 ods 电子表格文件转换为 csv,我可以在网络服务器 (Ubuntu 16.04) 上使用它。
我已经红色了:https://pypi.python.org/pypi/unotools
对于给定的示例效果很好。
还有这个:http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno-part-1v2
它应该做我想让它做的工作,但在我的环境中没有。
我认为我的问题在方法 Calc.store_to_url:
行抛出异常
component.store_to_url(url,'FilterName','Text - txt - csv (StarCalc)')
非常感谢您的提示。
异常
unotools.unohelper.ErrorCodeIOException: SfxBaseModel::impl_store 失败: 0x81a
完整来源
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)
URL 必须是 file://
格式。
url = convert_path_to_url('out/result.csv')
请参阅 https://pypi.python.org/pypi/unotools 中的 store_to_url
示例。
编辑:
要使用绝对路径,请选择其中之一;没有必要合并它们。
url = 'file:///home/me/out/result.csv'
url = convert_path_to_url('/home/me/out/result.csv')
要使用相对路径,首先通过调用 os.getcwd().
验证工作目录是否为“/home/me”
我需要一个命令行工具来将 excel 和 ods 电子表格文件转换为 csv,我可以在网络服务器 (Ubuntu 16.04) 上使用它。 我已经红色了:https://pypi.python.org/pypi/unotools 对于给定的示例效果很好。
还有这个:http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno-part-1v2 它应该做我想让它做的工作,但在我的环境中没有。
我认为我的问题在方法 Calc.store_to_url:
行抛出异常
component.store_to_url(url,'FilterName','Text - txt - csv (StarCalc)')
非常感谢您的提示。
异常
unotools.unohelper.ErrorCodeIOException: SfxBaseModel::impl_store 失败: 0x81a
完整来源
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)
URL 必须是 file://
格式。
url = convert_path_to_url('out/result.csv')
请参阅 https://pypi.python.org/pypi/unotools 中的 store_to_url
示例。
编辑:
要使用绝对路径,请选择其中之一;没有必要合并它们。
url = 'file:///home/me/out/result.csv'
url = convert_path_to_url('/home/me/out/result.csv')
要使用相对路径,首先通过调用 os.getcwd().
验证工作目录是否为“/home/me”