【问题标题】:PowerShell Script to automate data entry to OpenOffice Calc Spreadsheet用于自动将数据输入到 OpenOffice Calc 电子表格的 PowerShell 脚本
【发布时间】:2010-10-31 14:06:20
【问题描述】:

我希望能够使用 PowerShell 脚本自动将数据输入到 Open Office 电子表格,就像使用 PowerShell 可以自动执行 Excel 一样(请参阅此 Scripting Guy 示例)。这可能吗?

谢谢,MagicAndi

【问题讨论】:

标签: powershell openoffice.org powershell-1.0 calc


【解决方案1】:

可以使用 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,它应该更容易使用,但最近好像没有更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多