方法一:python
import os
import win32com.client as win32
def save_as_xlsx(fname):
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)
wb.SaveAs(fname+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
if __name__ == "__main__":
package = "C:\你的xls所在的文件夹\"
files = os.listdir(package)
for fname in files:
if fname.endswith(".xls"):
print(fname + "正在进行格式转换,请稍后~")
save_as_xlsx(package + fname)
print(fname + "格式转换完成O(∩_∩)O哈哈~")
else:
print("跳过非xls文件:"+fname)
方法二:excel VBA
1、在存放需批量修改扩展名表格的文件夹里新建一个空白表格,右键点击选择查看代码。
2、选择Sheet1 Worksheet
输入如下代码段
Dim iFile(1 To 100000) As String
Dim count As Integer
Sub xls2xlsx()
iPath = ThisWorkbook.Path
On Error Resume Next
count = 0
zdir iPath
For i = 1 To count
If iFile(i) Like "*.xls" And iFile(i) <> ThisWorkbook.FullName Then
MyFile = iFile(i)
FilePath = Replace(MyFile, ".xls", ".xlsx")
If Dir(FilePath, 16) = Empty Then
Set WBookOther = Workbooks.Open(MyFile)
Application.ScreenUpdating = False
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
WBookOther.Close SaveChanges:=False
Application.ScreenUpdating = True
End If
End If
Next
End Sub
Sub zdir(p)
Set fs = CreateObject("scripting.filesystemobject")
For Each f In fs.GetFolder(p).Files
If f <> ThisWorkbook.FullName Then count = count + 1: iFile(count) = f
Next
For Each m In fs.GetFolder(p).SubFolders
zdir m
Next
End Sub
3、点击运行→运行子过程,在弹出界面框点击运行。



