如何使用Powershell从excel中提取多个列

时间:2015-10-14 14:56:48

标签: excel powershell

所有

我有以下代码从XLS中提取一列。现在我需要提取两列。在这种情况下,我需要列D和E.我无法弄明白,帮助表示赞赏。谢谢!

$SMTPApprovedXLS = "c:\temp\SMTP\SMTPAPPLIST.XLS"
$SheetName = "Active"
$objExcel = New-Object -ComObject Excel.Application
$objExcel.Visible = $False
$Workbook = $objExcel.Workbooks.open($SMTPApprovedXLS)
$Worksheet = $Workbook.sheets.item($SheetName)
$startRow = 4

$ApprovedIPs = @()

$count = $Worksheet.Cells.Item(65536,4).End(-4162)

for($startRow=4; $startRow -le $count.row; $startRow++)
{
 $ApprovedIPs += $Worksheet.Cells.Item($startRow, 4).Value()
}

$ApprovedIPs | Out-File C:\ApprovedIPs.txt

0 个答案:

没有答案