我想把csv文件转换成xlsb。我使用这个Convert XLS to CSV on command line中的第二个答案,即下面的代码:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Please specify the source and the destination files. Usage: ExcelToCsv <xls/xlsx source file> <csv destination file>"
Wscript.Quit
End If
csv_format = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(1))
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
oBook.SaveAs dest_file, csv_format
oBook.Close False
oExcel.Quit
我的代码如下:
^{pr2}$问题是我找不到合适的值作为xlsb格式。我找到了这个XlFileFormat Enumeration (Excel),它有可用的值,但是我不确定我需要哪个值。在
有用提示:如果有人试图转换第一行第一项是ID的csv,就会出现错误。将ID改为ID就可以了,更多信息SYLK: File format is not valid。在
根据this,
xlsb
格式是xlExcel12
,值为50(Mac的Excel为51)。此外,您可以使用pywin32库来转换:相关问题 更多 >
编程相关推荐