Combreal

export-xlsm.ps1

Jan 31st, 2022 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $CustomLogInfos #my phat item
  2. $fileName = "my-file_2022.01.31_04.10.34"
  3. $delimiter = ","
  4. $directoryPath = "C:\Users\path\"
  5.  
  6. $csv = $directoryPath + $fileName + ".csv"
  7. $CustomLogInfos | Export-CSV -Path $csv -Force -NoTypeInformation
  8. $xlsx = $directoryPath + $fileName + ".xlsx"
  9. $excel = New-Object -ComObject excel.application
  10. $workbook = $excel.Workbooks.Add(1)
  11. $worksheet = $workbook.worksheets.Item(1)
  12. $TxtConnector = ("TEXT;" + $csv)
  13. $Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1"))
  14. $query = $worksheet.QueryTables.item($Connector.name)
  15. $query.TextFileOtherDelimiter = $delimiter
  16. $query.TextFileParseType  = 1
  17. $query.TextFileColumnDataTypes = ,1 * $worksheet.Cells.Columns.Count
  18. $query.AdjustColumnWidth = 1
  19. $query.Refresh()
  20. $query.Delete()
  21. $Workbook.SaveAs($xlsx,51)
  22. $excel.Quit()
  23. start excel.exe $xlsx
Add Comment
Please, Sign In to add comment