I am trying to convert over 600 files of .xml type into .xlsx type using this python script I found while searching around:
import sys
folder = '/FolderWithXMLFiles'
for filename in os.listdir(folder):
infilename = os.path.join(folder, filename)
if not os.path.isfile(infilename): continue
oldbase = os.path.splitext(filename)
newname = infilename.replace('.xml', '.xlsx')
os.rename(infilename, newname)
Although the code runs fine, the output is not what I expected as I keep getting an error in Excel saying "File format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
I have tried converting the .xml file into .xls too and it works, but I get an error message saying that the file type and file format are not the same, but it still allows me to open it. Converting .xls to .xlsx did not work either.
Also, I have a second batch of files, which are the same as the .xml ones, but those ones are saved as Strict Open XML files. I have the choice of converting either of the batches to plain .xlsx file type but neither of the batches are converting to how I want them.
I have thought of copying all of the data from the .xml files into a new plain .xlsx workbook for each .xml, however, I haven't been able to figure out how to write a python script for that.
Any help would be appreciated.