1

As the title states, is this possible? I found some scripts for XLS to XLSX, but not the other way around.

Can this be done with powershell?

Thanks

jes516
  • 145
  • 1
  • 2
  • 7
  • 1
    Yes, it can be done. If you can do it with a mouse you can do it in a script. Nothing is impossible. – E.V.I.L. Feb 10 '15 at 04:24

1 Answers1

4

Setup your variables

$Filepath = 'C:\Users\mad tom vane\Documents\Test1.xlsx'
$Filepath = Get-Item -Path $Filepath
$NewFilepath = Join-Path -path $Filepath.directory.fullname -ChildPath "$($Filepath.basename).xls"

Open Excel up

$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true #or false

I like to open in Read-Only

$Workbook = $Excel.Workbooks.Open($Filepath.fullname,[Type]::Missing,$true)

Save the workbook as xlExcel8 for an XLS file

$Workbook.SaveAs($NewFilepath,56)

#https://technet.microsoft.com/en-us/library/ff730962.aspx
$Workbook.Close()
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Remove-Variable Excel
E.V.I.L.
  • 238
  • 1
  • 2
  • 7
  • Any chance this script works on a 2003 server? Im thinking no since it looks like a rename process. – jes516 Feb 10 '15 at 05:24
  • I've tested this "script" (lines of code) on PowerShell 2.0 and it all works. http://support.microsoft.com/kb/968929?wa=wsignin1.0 – E.V.I.L. Feb 10 '15 at 05:40
  • my apologies, i meant will it work on the server if the server does not have excel/office 2007+ ? in other words, does the machine have to have the ability to create .xlsx files natively. the above works well on my 7 and 8.1 machines but i have office 2013 on both of them. the 2003 server only has office 2003. – jes516 Feb 10 '15 at 16:54
  • Good question. I don't have Office 2003 to test with. I'd just test it and see what errors arise. – E.V.I.L. Feb 10 '15 at 17:15
  • 2
    Also use `$Excel.DisplayAlerts = $false` to suppress the alert. – LoMaPh May 26 '20 at 21:50