使用Powershell保存打开的Excel工作表

使用Powershell保存打开的Excel工作表,powershell,Powershell,我对Powershell完全是新手。使用Powershell保存打开的excel工作表时需要您的帮助 脚本是这样的 $xlPasteValues = -4163 $xlCellTypeLastCell = 11 $xl = new-object -comobject excel.application $xl.Visible = $True $xl.DisplayAlerts = $False $wb = $xl.Workbooks.Add() $i = 1 $collection = Get-

我对Powershell完全是新手。使用Powershell保存打开的excel工作表时需要您的帮助

脚本是这样的

$xlPasteValues = -4163
$xlCellTypeLastCell = 11
$xl = new-object -comobject excel.application
$xl.Visible = $True
$xl.DisplayAlerts = $False
$wb = $xl.Workbooks.Add()
$i = 1
$collection = Get-ChildItem C:\Test\* -include *.csv  # Change the location of your CSV files here.
$length = 4
foreach ($item in $collection) {
    $wb1 = $xl.Workbooks.Open("$item")
    $array = $item.ToString()
    $delim = "\"
    $SheetName = $array.split($delim)
    $s = $SheetName[2]
    $sn = $s.split(".")
    $nsn = $sn[0]
    $ws1 = $wb1.worksheets | where {$_.name -eq $nsn}
Write-Host $item $nsn
$used = $ws1.usedRange
$used.Select()
$used.copy()
$wb.Activate()
$ws = $wb.Sheets.Add()
$ws2 = $wb.worksheets | where {$_.name -eq "sheet$i"}
[void]$ws2.Range("A1").PasteSpecial(-4163)
$ws2.name = $nsn
$i++ 
$wb1.Close()
}
Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$xlFixedFormat =[Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$Excel = New-Object -comobject Excel.Application
$Excel.Visible = $true

您的问题相当模糊,因此我假设您想知道如何通过Powershell打开和保存Excel文档

使用新对象打开Excel文档

保存并关闭文档


您的问题相当模糊,因此我假设您想知道如何通过Powershell打开和保存Excel文档

使用新对象打开Excel文档

保存并关闭文档


您的问题相当模糊,因此我假设您想知道如何通过Powershell打开和保存Excel文档

使用新对象打开Excel文档

保存并关闭文档


您的问题相当模糊,因此我假设您想知道如何通过Powershell打开和保存Excel文档

使用新对象打开Excel文档

保存并关闭文档


查看我的PowerShell Excel模块。你也可以

然后尝试:

$xlFileName="c:\temp\test.xlsx"    

dir *.csv | 
    ForEach {
        $sheetName=$_.Name.Split('.')[0]

        Import-Csv $_.FullName | 
            Export-Excel $xlFileName -WorkSheetname $sheetName
    }

Invoke-Item $xlFileName

查看我的PowerShell Excel模块。你也可以

然后尝试:

$xlFileName="c:\temp\test.xlsx"    

dir *.csv | 
    ForEach {
        $sheetName=$_.Name.Split('.')[0]

        Import-Csv $_.FullName | 
            Export-Excel $xlFileName -WorkSheetname $sheetName
    }

Invoke-Item $xlFileName

查看我的PowerShell Excel模块。你也可以

然后尝试:

$xlFileName="c:\temp\test.xlsx"    

dir *.csv | 
    ForEach {
        $sheetName=$_.Name.Split('.')[0]

        Import-Csv $_.FullName | 
            Export-Excel $xlFileName -WorkSheetname $sheetName
    }

Invoke-Item $xlFileName

查看我的PowerShell Excel模块。你也可以

然后尝试:

$xlFileName="c:\temp\test.xlsx"    

dir *.csv | 
    ForEach {
        $sheetName=$_.Name.Split('.')[0]

        Import-Csv $_.FullName | 
            Export-Excel $xlFileName -WorkSheetname $sheetName
    }

Invoke-Item $xlFileName

有什么问题?你试图解决什么问题?问题是什么?你试图解决什么问题?问题是什么?你试图解决什么问题?问题是什么?你试图解决什么问题?