gpt4 book ai didi

python - unotools - 尝试使用 python 将 ods 或 excel 文件转换为 csv

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:33 32 4
gpt4 key购买 nike

我需要一个命令行工具来将 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','文本 - 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” .

关于python - unotools - 尝试使用 python 将 ods 或 excel 文件转换为 csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42721321/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com