如何浏览Excel文件并查看特定列中单元格的内容?
我想浏览Excel文件并显示所有不为空的单元格(cx)的内容。
c = column 3
x = line in progress
我的代码仅显示第一个单元格的内容。 预先感谢您的帮助。
我的代码是:
$excel = new-object -comobject Excel.Application
$excel.visible = $true
$excel.DisplayAlerts = $False
$excel_file_path = 'C:UsersmahmaDesktopdoc1.xlsx'
$workbook = $excel.Workbooks.open($excel_file_path)
$SheetName = "Feuil1"
$Sheet = $Workbook.Worksheets.Item($SheetName)
$row = 2
$val= @() $Column = 3
$entries = $Sheet.Cells.Item($row,$column).Text
foreach ($entry in $entries) {
if ($entry -ne ""){
$val += $entry $row++
} else {
$excel.Quit()
}
} Write-Host $val