2009-06-05 62 views

回答

3

它使用UNO CLI绑定是可能的。不幸的是Powershell不能很好地处理代理对象,所以你需要使用反射。例如,

[System.Reflection.Assembly]::LoadWithPartialName('cli_basetypes') 
[System.Reflection.Assembly]::LoadWithPartialName('cli_cppuhelper') 
[System.Reflection.Assembly]::LoadWithPartialName('cli_oootypes') 
[System.Reflection.Assembly]::LoadWithPartialName('cli_ure') 
[System.Reflection.Assembly]::LoadWithPartialName('cli_uretypes') 
$localContext = [uno.util.Bootstrap]::bootstrap() 
$multiComponentFactory = [unoidl.com.sun.star.uno.XComponentContext].getMethod('getServiceManager').invoke($localContext, @()) 
$desktop = [unoidl.com.sun.star.lang.XMultiComponentFactory].getMethod('createInstanceWithContext').invoke($multiComponentFactory, @('com.sun.star.frame.Desktop', $localContext)) 
$calc = [unoidl.com.sun.star.frame.XComponentLoader].getMethod('loadComponentFromURL').invoke($desktop, @('private:factory/scalc', '_blank', 0, $null)) 
$sheets = [unoidl.com.sun.star.sheet.XSpreadsheetDocument].getMethod('getSheets').invoke($calc, @()) 
$sheet = [unoidl.com.sun.star.container.XIndexAccess].getMethod('getByIndex').invoke($sheets, @(0)) 
$cell = [unoidl.com.sun.star.table.XCellRange].getMethod('getCellByPosition').invoke($sheet.Value, @(0,0)) 
[unoidl.com.sun.star.table.XCell].getMethod('setFormula').invoke($cell, @('A value in cell A1.')) 

您也可以尝试AODL这应该是更容易使用,但并不像它的最近更新。

相关问题