2014-05-21 77 views
8

我只是全職移動到Linux和LibreOffice,但我想弄清楚如何在python中爲它實際編寫腳本。如何使用LibreOffice Calc和Python?

簡單的事情就像引用單元格/工作表等。使用python查找列中的最後一個單元格。

所有的事情在VBA中都非常容易,但現在我需要學習如何在Python中完成它們。

+0

軟件使用問題屬於superuser.com –

回答

2

也許OOSheet將是你在找什麼:

http://oosheet.hacklab.com.br/

它比一個更高的水平蟒蟒接口,UNO(這是用來作爲OOSheet低級別API)。您可以使用它來創建宏腳本,以及在通過套接字連接到libreoffice的shell中運行。這很好,因爲您可以使用IPython或其他交互式(REPL)shell在表單中工作或開發某些內容。

>>> from oosheet import OOSheet as S 
>>> S('a1').string = 'Hello world' 
>>> S('a1').value = 1 
>>> S('a2').formula = '=a1+10' 
>>> S('a2').value 
11.0 
>>> S('a2').string 
u'11' 
>>> S('a2').formula 
u'=A1+10' 
>>> S('a1').set_value(2).drag_to('a3').drag_to('b3') 
>>> S('a1:b3').data_array 
((2.0, 3.0), (3.0, 4.0), (4.0, 5.0)) 
>>> S('g5').string = 'hello world' 
>>> S('a1:10').shift_down_until(column_g_satisfies = lambda s: s.string.endswith('world')) 
Sheet1.G1:G10 
>>> S('a8:b8').cut() 
>>> S('a1:4').copy() 
>>> S('j5').paste() 
>>> S().undo() 
>>> S().redo() 
>>> S().save_as('/tmp/oosheet_sandbox.ods') 
>>> S().quit() # this will close LibreOffice 
2

你試過pyoo

這是從官方文檔演示瞭如何簡單一點的可以做什麼採取了示例代碼?它是某種Python-UNO包裝,似乎是直接使用Python-UNO的有效和簡單的替代方法。

相關問題