How to Convert Excel XML to XLS from the Command Line
Question details
The user needs a method to convert Excel XML report files to the older XLS format via the command line or a DLL so users with legacy Excel versions can open them without errors.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A third-party reporting tool generates reports in Excel XML format, which fail to open in older versions of Excel unless converted to the standard Excel 97-2003 (XLS) format.
- Observed behavior
- Simply renaming the file extension from .xml to .xls is unreliable and causes errors for users on older Excel versions, as it does not actually change the internal file structure.
Before attempting command-line conversion, verify that your original XML file is a properly structured Excel Spreadsheet XML and can be opened manually in a modern spreadsheet application.
Automate Excel 'Save As' Using a PowerShell Script
Since Excel lacks a native command-line conversion switch, you can write a PowerShell script using the Excel COM object to silently open the XML and save it as an XLS file.
Microsoft Excel does not offer a built-in executable parameter for converting file formats directly from the command prompt. However, you can achieve the exact equivalent of 'Save As Excel 97-2003 Workbook' by interacting with Excel's COM automation interface via a script.
Open Notepad and start a new PowerShell script. Create the Excel application object using the command: $excel = New-Object -ComObject Excel.Application.
Instruct the script to open your target XML report by adding: $workbook = $excel.Workbooks.Open('C:\path\to\your\report.xml').
Save the file in the XLS format (Format ID 56) by adding: $workbook.SaveAs('C:\path\to\output.xls', 56).
Save your script as 'Convert-XMLtoXLS.ps1'. You can now trigger this conversion from the command line by executing: powershell.exe -ExecutionPolicy Bypass -File Convert-XMLtoXLS.ps1.

Use Dedicated Command-Line Conversion Tools
If you need to convert files on a server where Excel is not installed, utilize a third-party document conversion utility or DLL.
Manually Save As Excel 97-2003 Workbook
If automation proves too complex, the most reliable fallback is manually converting the files before distributing them to users with older software.
Easily Convert XML Reports to XLS with WPS Spreadsheet
If you are dealing with frequent format compatibility issues, WPS Office offers a free, lightweight solution. WPS Spreadsheet seamlessly opens Excel XML reports and allows you to quickly save them as highly compatible XLS files, ensuring users on legacy systems can access their data without errors.
- 1. Open your XML file in WPS: Launch WPS Spreadsheet and drag-and-drop your generated XML report directly into the workspace.
- 2. Click on Save As: Click the Menu button in the top left corner, then hover over the 'Save As' option.
- 3. Save in XLS format: Select 'Microsoft Excel 97-2003 Workbook (*.xls)' from the available options to create a fully compatible file.

Frequently Asked Questions
Why does renaming an XML file to XLS not work?
Changing a file's extension only changes its name, not its underlying data structure. An XML file is text-based, whereas a true legacy XLS file is a binary format. Older Excel versions expect the binary structure and will throw an error if they encounter plain text XML.
Are there standard Excel command-line switches to convert file formats?
No. Microsoft Excel does not provide native command-line parameters (like a simple switch) to convert files from one format to another or to trigger the 'Save As' command silently.
Can I automate this conversion on a background server?
While it is possible to use COM automation via PowerShell or VBScript, Microsoft explicitly advises against automating Office applications in an unattended server environment. For servers, it is highly recommended to use dedicated third-party conversion DLLs or APIs.
What is the correct file format ID for saving as XLS via COM?
When using the SaveAs method in an automation script, the file format ID for an Excel 97-2003 Workbook (.xls) is 56.




