0
我想能夠自動數據輸入到使用PowerShell腳本的開放式辦公室電子表格,以同樣的方式,Excel可以使用PowerShell自動化(見本Scripting Guy例子) 。這可能嗎?PowerShell腳本來自動數據輸入到OpenOffice Calc電子表格
感謝,MagicAndi
我想能夠自動數據輸入到使用PowerShell腳本的開放式辦公室電子表格,以同樣的方式,Excel可以使用PowerShell自動化(見本Scripting Guy例子) 。這可能嗎?PowerShell腳本來自動數據輸入到OpenOffice Calc電子表格
感謝,MagicAndi
它使用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這應該是更容易使用,但並不像它的最近更新。
看起來像一個愚蠢http://stackoverflow.com/questions/954926/using-a-script-to-automate-data-entry-to-an-openoffice-calc-spreadsheet – Helen 2009-06-06 11:47:50