?
Rem http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlfileformat.aspxSet objArgs = WScript.ArgumentsFullName = objArgs(0)FileName = Left(FullName, InstrRev(FullName, ".")-1)Set objExcel = CreateObject("Excel.application")objExcel.application.visible=falseobjExcel.application.displayalerts=falseset objExcelBook = objExcel.Workbooks.Open(FullName)objExcelBook.SaveAs FileName & "(SysAutoConv)",51objExcel.Application.QuitobjExcel.Quit Set objExcel = Nothingset objExcelBook = Nothing
?
?
?
?
import java.io.IOException;/** * * @author lidongbo * @date 2012-10-15 */public class VBAUtils { public static final void xls2xlsx(String filePath) throws IOException{ //TODO:测试 Runtime.getRuntime().exec("cscript \"" + "C:\\aaa\\xls2xlsx.vbs\" \"" + filePath + "\""); } public static void main(String[] args) throws IOException { xls2xlsx("C:\\aaa\\aaa.xls"); }}
?
?
?
如果出现以下异常
Microsoft Office Excel 不能访问文件“XXXxls”。 可能的原因有:? 文件名称或路径不存在。? 文件正被其他程序使用。?? 您正要保存的工作簿与当前打开的工作簿同名
?
解决办法如下
?Windows 2008 Server x64?
? Please make this folder.
? C:\Windows\SysWOW64\config\systemprofile\Desktop
?Windows 2008 Server x86
? Please make this folder.
? C:\Windows\System32\config\systemprofile\Desktop
? ...instead of dcomcnfg.exe.
This operation took away office automation problems in my system.
A Desktop folder seems to be necessary in the systemprofile folder to open file by Excel.
It disappears from Windows2008, Windows2003 had the folder,?
and I think it cause this error.
?
在C:\Windows\System32\config\systemprofile和C:\Windows\SysWOW64\config\systemprofile目录下创建名为Desktop目录即可解决问题。
?