I am using powershell to generate some reports. The reports are generally created in CSV format, with double quotes around each field.
However, some recipients want to receive these in Excel format. I have created a script to take the csv output, and create a xls file from this.
$ExtractFilePath = "Directory/Original_File_Name.csv"
$ExcelFilePath = "Directory/Excel_File_Name.xls"
$xl = new-object -comobject excel.application
$xl.visible = $true
$Workbook = $xl.workbooks.open("$ExtractFilePath")
$Worksheets = $Workbooks.worksheets
$Workbook.SaveAs("$ExcelFilePath",1)
$Workbook.Saved = $True
$xl.Quit()
This works well for most instances, however, I have one report that contains fields with leading zeros. These are dropped in the excel file.
Is there a way to format all of the cells in the workbook as text so that the leading zeros are preserved.
Thanks.