powershell - 在工作表中,如果在 A5 单元格中找到一个单词,则要使用 PowerShell 复制 B5 单元格值
问题描述
在 Excel 中有 2 列具有 A 和 B 值。如果在 A5 单元格中找到“勇气”一词,那么我想复制 B5 单元格的值。
如果“勇气”一词在 A10 中,则复制 B10 值(对面单元格)。我已经准备好下面的脚本来鼓起勇气,它工作正常但无法复制相反的单元格值。
$Excel = New-Object -ComObject Excel.Application
$Workbook = $Excel.Workbooks.Open('C:\Users\Raj\Desktop\Book1.xlsx')
$workSheet = $Workbook.Sheets.Item(1)
$WorkSheet.Name
$Found = $WorkSheet.Cells.Find('courage')
If ($Found.)
解决方案
试试这个 -
$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
推荐阅读
- python - _tkinter.TclError:无效的命令名称“.!entry”
- sql - 将列添加到 SQL 表并使用该列的一组固定值分解行
- javascript - 使用包装反应应用程序的优点是什么
与直接使用 javascript 进行突变和查询相比 - c++ - 在构造函数中初始化参数的构造
- reactjs - React Redux 错误:redux.js:275 未捕获错误:操作必须是普通对象。相反,实际的类型是:'Promise'
- javascript - JavaScript:是否可以创建一个数组,每个数组元素都有多个值?
- java - 获取负载 JWT
- ios - 在 ContentView.swift 中编写时不允许在顶层使用表达式
- javascript - CSS ReactJs - 你可能需要一个合适的加载器来处理这个文件类型,目前没有配置加载器来处理这个文件
- python - Python 和 Selenium,我是否必须多次获取 url 才能发生更改?