![](/img/trans.png)
[英]Excel VBA. Copy data from multiple workbooks and paste in one workbook same worksheet
[英]Copy Excel Data with the Same Name of Worksheet from Multiple Workbooks using Powershell
我不知道如何解釋,但我正在嘗試使用 Powershell 創建一個比較工具。 我有多個源文件,其中包含與其他文件具有相同名稱的多個工作表。 我正在嘗試復制 File_1 下的“VALUE”以及 File_2 和 File_3,並將其粘貼到 Output 文件的第二行,具體取決於文件名和工作表名稱,並將其保存為新的 Output 文件。
我正在關注這篇文章: https://stackoverflow.com/a/23742718/19614816但這些只獲取每個文件的第一張並將其粘貼到一張中。 我的問題是如何獲取相同工作表名稱下的每個工作表的值並將其粘貼到 Output 文件中並生成與源工作表相同的新工作表名稱。
源文件中的工作表:
另一個問題是 idk 或者有沒有辦法過濾源文件,因為我只想比較 File_1,2,3 和 File_1,3,4 等...
Output 文件的示例模板:
示例源文件:
感謝您花時間解決這個問題:)
我想你想知道如何遍歷一本書中的所有工作表。
# $source = $excel.Workbooks.Open($File)
#Loop through sheets
for ($i = 1; $i -le $source.Sheets.Count; $i++){
$currentSheet = $source.Sheets($i)
#Do something on $currentSheet
}
對於第二個問題,我會像下面那樣做。
# make a list for file you would like to look up
$files = @("File1.xlsx","File2.xlsx","File3.xlsx")
# loop through $files
for ($j = 0; $j -lt $files.Count; $j++){
$FullPath = (Get-ChildItem -Path $files[$j]).FullName
$source = $excel.Workbooks.Open($FullPath)
#Do something on $source
}
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.