Tôi đang cố gắng tạo chương trình python (sử dụng pyUNO) để thực hiện một số thay đổi trên bảng tính OpenOffice.Tải tài liệu về OpenOffice bằng chương trình Python bên ngoài
Tôi đã khởi chạy OpenOffice trước đó ở chế độ "chấp nhận" để có thể kết nối từ một chương trình bên ngoài. Rõ ràng, nên càng dễ dàng như:
import uno
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
# connect to the running office
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;"
"urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
# get the central desktop object
DESKTOP =smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
#The calling it's not exactly this way, just to simplify the code
DESKTOP.loadComponentFromURL('file.ods')
Nhưng tôi nhận được một AttributeError
khi tôi cố gắng để truy cập loadComponentFromURL
. Nếu tôi thực hiện một dir(DESKTOP)
, tôi đã nhìn thấy chỉ các thuộc tính/phương pháp sau đây:
['ActiveFrame', 'DispatchRecorderSupplier', 'ImplementationId', 'ImplementationName',
'IsPlugged', 'PropertySetInfo', 'SupportedServiceNames', 'SuspendQuickstartVeto',
'Title', 'Types', 'addEventListener', 'addPropertyChangeListener',
'addVetoableChangeListener', 'dispose', 'disposing', 'getImplementationId',
'getImplementationName', 'getPropertySetInfo', 'getPropertyValue',
'getSupportedServiceNames', 'getTypes', 'handle', 'queryInterface',
'removeEventListener', 'removePropertyChangeListener', 'removeVetoableChangeListener',
'setPropertyValue', 'supportsService']
Tôi đã đọc rằng có những nơi một lỗi làm giống nhau, nhưng trên OpenOffice 3.0 (Tôi đang sử dụng OpenOffice 3.1 trên Red Hat5.3). Tôi đã cố gắng sử dụng giải pháp thay thế được nêu là here, nhưng chúng dường như không hoạt động.
Bất kỳ ý tưởng nào?
Phương pháp này không được tìm thấy, như tôi đã cố gắng để có được những phương pháp itsef, gọi không có tham số từ vỏ tương tác: - (Tôi cũng đã cố gắng gọi nó với bốn tham số, tôi đã đơn giản hóa nó một cách có chủ ý. – Khelben