使用命令行将.CSV转换为.XLSX [英] Convert .CSV to .XLSX using command line

查看:1416
本文介绍了使用命令行将.CSV转换为.XLSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将一系列 .csv 文件批量转换为 .xlsx 的方法命令行。

I'm looking for a way to batch-convert a series of .csv files to .xlsx using the command line.

我试过一堆不同的VBScripts,我发现,但他们似乎正在转换 .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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆