如何从所有excel文件导入特定列并将其导出为新excel文件中的表?

时间:2015-03-02 23:20:24

标签: excel powershell

$excel_test = New-Object -ComObject Excel.Application

$excel_test.visible =$false
$excel_test.DisplayAlerts =$true

$excelFiles = Get-ChildItem -Path C:\Users\Lab-User\Documents\NDVI_2_Working -Include *.xlsx -Recurse

    Foreach ($file in $excelFiles)
                            {
                               $workbook = $excel_test.Workbooks.open($file)
                               $Worksheet = $Workbook.WorkSheets.item("Sheet2")
                               $range = $WorkSheet.range("A1:AC1").EntireColumn 
                               $averages=$range.Copy("AB1").EntireColumn 
    $averages.SaveAs("C:\Users\Lab-User\Documents\NDVI_2_Working\Summary.xlsx")
                       }

我不断收到“范围类的复制方法失败”的错误。

0 个答案:

没有答案