使用命令行将 .CSV 转换为 .XLSX [英] Convert .CSV to .XLSX using command line
本文介绍了使用命令行将 .CSV 转换为 .XLSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种使用命令行将一系列 .csv
文件批量转换为 .xlsx
的方法.
I'm looking for a way to batch-convert a series of .csv
files to .xlsx
using the command line.
我尝试了一堆我发现的不同 VBScript,但它们似乎都将 .xlsx
转换为 .csv
而不是相反.
I have tried a bunch of different VBScripts that I found but they all seem to be converting .xlsx
to .csv
and not the other way around.
这是我能找到的最接近的一个,但同样是 .xlsx
到 .csv
:
Here is the closest one I could find but again it's .xlsx
to .csv
:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
有什么想法吗?
推荐答案
唯一的先决条件是文件名中的.csv"必须是小写:
only pre-requisite is that the ".csv" must be lower case in the filename:
Dim file, WB
With CreateObject("Excel.Application")
On Error Resume Next
For Each file In WScript.Arguments
Set WB = .Workbooks.Open(file)
WB.SaveAs Replace(WB.FullName, ".csv", ".xlsx"), 51
WB.Close False
Next
.Quit
End With
WScript.Echo "Done!"
这篇关于使用命令行将 .CSV 转换为 .XLSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文