Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不带Office套件的ComObject Excel应用程序_Excel_Powershell_Ms Office_Powershell 2.0 - Fatal编程技术网

不带Office套件的ComObject Excel应用程序

不带Office套件的ComObject Excel应用程序,excel,powershell,ms-office,powershell-2.0,Excel,Powershell,Ms Office,Powershell 2.0,我需要从Powershell读取Excel文件。 我正在使用此对象: $objExcel=New-Object -ComObject Excel.Application 在安装了Office的机器上工作正常,但如果未安装Office,则会出现以下错误: Retrieving the COM class factory for component with CLSID {} failed due to the following error: 80040154 Class not registe


我需要从Powershell读取Excel文件。
我正在使用此对象:

$objExcel=New-Object -ComObject Excel.Application
在安装了Office的机器上工作正常,但如果未安装Office,则会出现以下错误:

Retrieving the COM class factory for component with CLSID {} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Office是否有一些运行时环境可供使用?

没有运行时,如Access

这里有一个查看器,如果有帮助的话

概述

使用Excel Viewer,即使未安装Excel,也可以打开、查看和打印Excel工作簿。你也可以复制 数据从Excel Viewer传输到另一个程序。但是,您不能编辑 数据、保存工作簿或创建新工作簿

没有Excel的“运行时”可供您在未获得适当的Excel许可证(并在计算机上安装Excel)的情况下使用。如果您试图在多个用户的服务器OS上进行此操作,那么您也需要考虑特殊许可(因为单个Excel许可证不可能覆盖多个用户)。

您可以考虑使用一种类似于文档的方式执行Excel文件中的一些常见操作。由于它是一个.NET库,您可以从PowerShell中使用它。

可以使用Active X数据对象(ADO)代替COM,例如

资料来源:

$strFileName = "C:\Data\scriptingGuys\Servers.xls"
$strSheetName = 'ServerList$'
$strProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
$strDataSource = "Data Source = $strFileName"
$strExtend = "Extended Properties=Excel 8.0"
$strQuery = "Select * from [$strSheetName]"

$objConn = New-Object System.Data.OleDb.OleDbConnection("$strProvider;$strDataSource;$strExtend")
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand($strQuery)
$sqlCommand.Connection = $objConn
$objConn.open()

$DataReader = $sqlCommand.ExecuteReader()

While($DataReader.read())
{
 $ComputerName = $DataReader[0].Tostring() 
 "Querying $computerName ..."
 Get-WmiObject -Class Win32_Bios -computername $ComputerName
}  
$dataReader.close()
$objConn.close()