Hi,
Why not convert it to a csv file? It's much easier.
$source = "C:\Users\rnoy\Parse-html\inputfile.txt"
$destination = "C:\Users\rnoy\Parse-html\outputfile.csv"
Get-Content -Path $source | ForEach-Object {
($_ -split " " | Where-Object { $_ }) -join ","
} | ConvertFrom-Csv | Export-Csv -NoTypeInformation -Path $destination
If you do need an xlsx file you can convert the csv file like this
$xlsxFile = "C:\Users\rnoy\Parse-html\outputfile.xlsx"
$xlFileFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$excel = New-Object -ComObject "Excel.Application"
$workbook = $excel.Workbooks.Open($destination)
$workbook.SaveAs($xlsxFile,$xlFileFormat)
$workbook.Close()
$excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.