Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Convert all XLSB files to XLSX

henrygeorge
8 - Asteroid

Hi, 

 

Is there a code i can run in say Run Command tool (cmd) to convert any XLSB files in a directory and convert them to XLSX

 

Thanks,

2 REPLIES 2
Hammad_Rashid
11 - Bolide

To automate the conversion of XLSB files to XLSX using a command-line interface, you can use PowerShell.

 

Here's a simple PowerShell script that you can run in the Command Prompt (cmd):

 

# Set the path to the directory containing XLSB files
$directoryPath = "C:\Path\To\Your\Directory"

 

# Get all XLSB files in the specified directory
$xlsbFiles = Get-ChildItem -Path $directoryPath -Filter *.xlsb

 

# Loop through each XLSB file and convert it to XLSX
foreach ($xlsbFile in $xlsbFiles) {
$xlsxFileName = [System.IO.Path]::ChangeExtension($xlsbFile.FullName, "xlsx")
$excel = New-Object -ComObject Excel.Application
$workbook = $excel.Workbooks.Open($xlsbFile.FullName)
$workbook.SaveAs($xlsxFileName, 51) # 51 corresponds to the XLSX file format
$workbook.Close()
$excel.Quit()
}

 

# Release Excel COM objects
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)

Write-Host "Conversion completed."

 

Save this script with a .ps1 extension (e.g., ConvertXLSBtoXLSX.ps1) and run it using PowerShell. Make sure to change the $directoryPath variable to the path of your directory containing XLSB files.

 

Note: The script uses COM objects to interact with Excel, so you need to have Excel installed on the machine where you run the script. Also, be aware that running scripts requires appropriate permissions, and you might need to adjust your PowerShell execution policy accordingly.

 

 

If you prefer to use the command prompt instead of PowerShell, you can use the following command to convert all XLSB files in a directory to XLSX format:

"C:\Program Files (x86)\Microsoft Office\Office12\excelcnv.exe" -oice <path to XLSB file> <path to XLSX file>

Replace <path to XLSB file> with the path to the XLSB file that you want to convert and <path to XLSX file> with the path where you want to save the converted XLSX file. You can also use wildcards to convert multiple files at once.

 

 

henrygeorge
8 - Asteroid

@Hammad_Rashid Thank you i tried to use below in command prompt

"C:\Program Files (x86)\Microsoft Office\Office12\excelcnv.exe" -oice "C:\data\Folder with binary files\*.xlsb" "C:\data\Output folder of all xlsx files\*.xlsx"

 

This seems to not work for me - is above correct?

Also i want to ensure that my xlsx files have the same file name as the xlsb files

Is this posssible?

Labels