Сначала запускается сервер Libreoffice
Код: Выделить всё
soffice.exe --calc --norestore --nologo --minimized --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
Далее скрипт командует сервером
Код:
# -*- coding: utf-8 -*-
import sys,uno,unohelper,string
from com.sun.star.beans import PropertyValue
from com.sun.star.beans.PropertyState import DIRECT_VALUE
local = uno.getComponentContext()
resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
props = []
props.append(PropertyValue('FilterOptions',0,'UTF8',DIRECT_VALUE))
props.append(PropertyValue('ReadOnly',0,True,DIRECT_VALUE))
props.append(PropertyValue('RepairPackage',0,False,DIRECT_VALUE))
props.append(PropertyValue("Minimized",0,True,DIRECT_VALUE))
#props.append(PropertyValue("Hidden",0,True,DIRECT_VALUE)) Работает некорректн о листами
inputFile = "file:///D:/test.xls"
document = desktop.loadComponentFromURL(inputFile, "_blank", 0, (tuple(props)))
#Выбор листа
if hasattr(document, 'getSheets'):
print ('Атрибут найден getSheets')
sheets = document.getSheets()
sheet = sheets.getByName('Лист2')
document.CurrentController.setActiveSheet(sheet)
#Замена на листе
if hasattr(sheet, 'createReplaceDescriptor'):
print ('Атрибут найден createReplaceDescriptor')
search=sheet.createReplaceDescriptor()
search.SearchString='\n'
#search.SearchString='ллл'
search.ReplaceString='_'
search.SearchWords = 0
search.SearchRegularExpression = 1
sheet.replaceAll(search)
props = []
props.append(PropertyValue("FilterName",0,"Text - txt - csv (StarCalc)",DIRECT_VALUE))
props.append(PropertyValue("FilterOptions",0,"59,34,76,1,,0,true,true,false",DIRECT_VALUE))
#Сохранение с параметрами
document.storeAsURL("file:///D:/002.csv",(tuple(props)))
document.dispose()
sys.exit()
Может ком сгодится