在Excel中,有2列具有A和B值。如果在A5单元格中找到“勇气”一词,那么我要复制B5单元格的值。
如果“勇气”一词出现在A10中,则复制B10值(对面的单元格)。我已经准备好以下脚本,以鼓起勇气使其正常工作,但无法复制相反的单元格值。
[at]
答案 0 :(得分:1)
尝试一下-
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Excel.DisplayAlerts = $false
$Workbook = $Excel.Workbooks.Open('C:\Users\Raj\Desktop\Book1.xlsx')
$workSheet = $Workbook.Sheets.Item(1)
$column = 1
$LastRow = $workSheet.UsedRange.Rows.Count
for($row=1; $row -lt $LastRow; $row++)
{
if ($WorkSheet.Cells.Item($row, $column).Value2 -eq "courage")
{
$WorkSheet.Cells.Item($row, $column+1).Value2 = $WorkSheet.Cells.Item($row, $column).Value2
}
}
#Proceed with other operations
#else save the worksheet and workbook
#Quit excel after you are done