【发布时间】:2018-09-25 12:53:17
【问题描述】:
是否有任何方法可以使用上面尝试的 power shell 从 Excel 中的列复制和粘贴是我的脚本。我想在另一张纸上粘贴大约 30 列。我已经厌倦了各种组合..我可以复制,但在粘贴行时,例如O2 行失败了。
我希望列 A1:A 被复制到行 O2,P2 ,r2 .... 它就像从列转置到行。我没有收到任何错误。基本上,它不是从列复制到行。尝试给出第 2 行和第 2 列 Row++,但没有成功。
下面的方法是累的方法之一。
$path = Read-Host -Prompt ("Enter the Sheet Location")
$xl = New-Object -ComObject excel.application
$xl.visible = $true
$wbk = $xl.Workbooks.open($path)
$ws1 = $wbk.WorkSheets.item("Old Data")
$ws2 = $wbk.WorkSheets.item("New Data")
$ws1.activate()
#Pasting Specific Name from first column
$xlPasteValues = -4163 # Values only, not formulas
$xlCellTypeLastCell = 11 # to find last used cell
$used = $ws1.usedRange
$lastCell = $used.SpecialCells($xlCellTypeLastCell)
$column = $lastCell.column
$range = $ws1.UsedRange
[void]$ws1.Range("A2$column").Copy()
[void]$ws2.Range("O18:O18").PasteSpecial(-4163)
$ws2.activate()
#Pasting Monthly perfomance
$xlPasteValues = -4163 # Values only, not formulas
$xlCellTypeLastCell = 11 # to find last used cell
$used = $ws1.usedRange
$lastCell = $used.SpecialCells($xlCellTypeLastCell)
$column = $lastCell.column
$range = $ws1.UsedRange
[void]$ws1.Range("B2$column").Copy()
[void]$ws2.Range("O8:O8").PasteSpecial(-4163)
$ws2.activate()
【问题讨论】:
标签: excel powershell