File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed
Scripts/Conversion and Format Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ Add-Type - AssemblyName " System.Windows.Forms"
2+
3+ function Show-OpenFileDialog {
4+ $dialog = New-Object System.Windows.Forms.OpenFileDialog
5+ $dialog.Filter = " CSV Files (*.csv)|*.csv"
6+ $dialog.Title = " Select CSV File"
7+ if ($dialog.ShowDialog () -eq " OK" ) {
8+ return $dialog.FileName
9+ }
10+ return $null
11+ }
12+
13+ function Show-SaveFileDialog {
14+ $dialog = New-Object System.Windows.Forms.SaveFileDialog
15+ $dialog.Filter = " Excel Workbook (*.xlsx)|*.xlsx"
16+ $dialog.Title = " Save Excel File"
17+ if ($dialog.ShowDialog () -eq " OK" ) {
18+ return $dialog.FileName
19+ }
20+ return $null
21+ }
22+
23+ $inputFile = Show-OpenFileDialog
24+ if (-not $inputFile ) {
25+ Write-Host " No CSV file selected. The script will be canceled."
26+ exit
27+ }
28+
29+ $outputFile = Show-SaveFileDialog
30+ if (-not $outputFile ) {
31+ Write-Host " No Excel file selected. The script will be canceled."
32+ exit
33+ }
34+
35+ Install-Module - Name ImportExcel - Scope CurrentUser - Force - AllowClobber
36+ Import-Csv $inputFile | Export-Excel - Path $outputFile - WorksheetName " Sheet1"
Original file line number Diff line number Diff line change 1+ Add-Type - AssemblyName " System.Windows.Forms"
2+
3+ function Show-OpenFileDialog {
4+ $dialog = New-Object System.Windows.Forms.OpenFileDialog
5+ $dialog.Filter = " Excel Files (*.xlsx)|*.xlsx"
6+ $dialog.Title = " Select Excel File"
7+ if ($dialog.ShowDialog () -eq " OK" ) {
8+ return $dialog.FileName
9+ }
10+ return $null
11+ }
12+
13+ function Show-SaveFileDialog {
14+ $dialog = New-Object System.Windows.Forms.SaveFileDialog
15+ $dialog.Filter = " CSV Files (*.csv)|*.csv"
16+ $dialog.Title = " Save CSV File"
17+ if ($dialog.ShowDialog () -eq " OK" ) {
18+ return $dialog.FileName
19+ }
20+ return $null
21+ }
22+
23+ $inputFile = Show-OpenFileDialog
24+ if (-not $inputFile ) {
25+ Write-Host " No Excel file selected. The script will be canceled."
26+ exit
27+ }
28+
29+ $outputFile = Show-SaveFileDialog
30+ if (-not $outputFile ) {
31+ Write-Host " No CSV file selected. The script will be canceled."
32+ exit
33+ }
34+
35+ $excel = New-Object - ComObject Excel.Application
36+ $workbook = $excel.Workbooks.Open ($inputFile )
37+ $worksheet = $workbook.Worksheets.Item (1 )
38+ $worksheet.UsedRange | Export-Csv - Path $outputFile - NoTypeInformation
39+ $workbook.Close ($false )
40+ $excel.Quit ()
41+ [System.Runtime.Interopservices.Marshal ]::ReleaseComObject($excel ) | Out-Null
You can’t perform that action at this time.
0 commit comments