[英]How to read an Excel file in PowerShell on Linux?
许多人都知道,PowerShell 现在可以在 Linux 上安装和使用,到目前为止,它对我来说工作得非常好。 但是,鉴于无法在 Linux 上安装 Excel,我想知道是否可以读取 Excel 文件的内容。 我在网上找到的是打开 Excel 文件的 PS 脚本是:
# Script copied and pasted from https://stackoverflow.com/questions/48443536/how-to-read-excel-files-in-powershell
$excel = New-Object -com excel.application
$wb = $excel.workbooks.open("c:\users\administrator\my_test.xls")
但我得到了错误:
New-Object: A parameter cannot be found that matches parameter name 'com'.
当我删除参数并运行脚本时,这是我得到的错误:
New-Object: Cannot find type [excel.application]: verify that the assembly containing this type is loaded.
Since I'm on Linux (ubuntu 22.04), I can use xls2csv
on bash to convert the Excel file to csv and then use Get-Content
on PowerShell. 但我想知道是否有办法在 PowerShell 上做到这一点,因为我目前正在学习它。
谢谢你。
我感谢@Olaf 指出了 Doug Finke 的ImportExcel模块。
安装模块后:
Install-Module -Name ImportExcel
导入文件很简单:
$data = Import-Excel c:\users\administrator\my_test.xls
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.