标题: [文件操作] 如何用批处理把Excel文件xls表格改成xlsx表格? [打印本页]
作者: xin_fei_ 时间: 2019-9-4 14:37 标题: 如何用批处理把Excel文件xls表格改成xlsx表格?
大神好,我们系统中默认导出的表格格式是.xls格式,97-2003格式的表格,现在我想用bat把这个表格的格式改成.XLSX的格式,2007格式的表格,请问有没有什么好的批处理的方法。
我是为了转成2007格式的表格之后,然后自动导入到数据模型中进行计算的,数据模型中不识别97-2003格式的表格。
我尝试了用这个代码,发现不行,没有改成功。请各位大神帮忙给想想解决方法,谢谢。复制代码
作者: Batcher 时间: 2019-9-4 14:46
没有改成功是指文件扩展名没有修改?还是文件扩展名修改了但是数据模型不识别?
作者: 小渣飞 时间: 2019-9-4 18:39
*..xls是不是多加了个点
作者: Batcher 时间: 2023-10-9 16:51
xls转xlsx - 单个文件.bat- # & cls & @cd /d "%~dp0" & powershell "Get-Content '%~0' | Out-String | Invoke-Expression " & exit /b
- $Excel = New-Object -ComObject Excel.Application
- $Excel.Visible = $false
- $Workbook = $Excel.Workbooks.Open("C:\Test\Excel\1.xls")
- $Workbook.CheckCompatibility = $false
- $Workbook.SaveAs("C:\Test\Excel\1.xlsx", 51)
- $Workbook.Close()
- $Excel.Quit()
复制代码
xls转xlsx - 多个文件.bat- # & cls & @cd /d "%~dp0" & powershell "Get-Content '%~0' | Out-String | Invoke-Expression " & exit /b
- $OldFolder = "C:\Test\From"
- $NewFolder = "C:\Test\To"
- $Excel = New-Object -ComObject Excel.Application
- $Excel.Visible = $false
- Get-ChildItem -Path $OldFolder\*.xls -File | ForEach-Object {
- $NewName = $NewFolder + "\" + $_.BaseName + ".xlsx"
- "[From] " + $_.FullName
- "[To] " + $NewName
- $Workbook = $Excel.Workbooks.Open($_.FullName)
- $Workbook.CheckCompatibility = $false
- $Workbook.SaveAs($NewName, 51)
- $Workbook.Close()
- }
- $Excel.Quit()
复制代码
xlsx转xls - 单个文件.bat- # & cls & @cd /d "%~dp0" & powershell "Get-Content '%~0' | Out-String | Invoke-Expression " & exit /b
- $Excel = New-Object -ComObject Excel.Application
- $Excel.Visible = $false
- $Workbook = $Excel.Workbooks.Open("C:\Test\Excel\1.xlsx")
- $Workbook.CheckCompatibility = $false
- $Workbook.SaveAs("C:\Test\Excel\2.xls", 56)
- $Workbook.Close()
- $Excel.Quit()
复制代码
xlsx转xls - 多个文件.bat- # & cls & @cd /d "%~dp0" & powershell "Get-Content '%~0' | Out-String | Invoke-Expression " & exit /b
- $OldFolder = "C:\Test\From"
- $NewFolder = "C:\Test\To"
- $Excel = New-Object -ComObject Excel.Application
- $Excel.Visible = $false
- Get-ChildItem -Path $OldFolder "*.xlsx" | ForEach-Object {
- $NewName = $NewFolder + "\" + $_.BaseName + ".xls"
- "[From] " + $_.FullName
- "[To] " + $NewName
- $Workbook = $Excel.Workbooks.Open($_.FullName)
- $Workbook.CheckCompatibility = $false
- $Workbook.SaveAs("$NewName", 56)
- $Workbook.Close()
- }
- $Excel.Quit()
复制代码
作者: GNGW 时间: 2024-3-6 13:39
回复 4# Batcher
这个带$符号不是powershell吗?
作者: Batcher 时间: 2024-3-6 14:18
回复 5# GNGW
第一行代码的作用是在bat里面调用powershell
这是bat和powershell混编的一种用法
作者: GNGW 时间: 2024-3-7 14:27
回复 6# Batcher
牛啊
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |