Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

CSV to Excel with pivot table

$
0
0

So I am trying to write a easy code to convert a csv to excel, insert a pivot table and then save it. the below code runs fine but the excel file is being saved with the name $name instead of the content of $name... and also can I use VBA code in powershell script ? I want to insert a pivot table and I can only find vba code for it....

Add-Type -AssemblyName System.Windows.Forms

$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{

InitialDirectory = [Environment]::GetFolderPath('Desktop')

Filter = 'SpreadSheet (*.csv)|*.csv'

}

$FileBrowser.ShowDialog()

$file = $FileBrowser.FileName

$name= $FileBrowser.SafeFileName

Write-Host $name

$excel = New-Object -ComObject Excel.Application

$excel.Visible = $true

$excel.DisplayAlerts = $false

$excel.Workbooks.Open($file)

$excel.Workbooks.item(1).SaveAs('C:\Users\User\Desktop\$name.xlsx',51)

$excel.Quit()

Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>