欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

python保存为xlsb_如何使用Python将csv文件转换为xlsb?

发布时间:2024/3/26 57 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python保存为xlsb_如何使用Python将csv文件转换为xlsb? 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我想将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 "

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

我的代码如下:

import subprocess

subprocess.call("cscript CsvToExcel.vbs data.csv data.xlsb",

stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) # Supress any messages

问题是我找不到正确的值作为xlsb格式.我发现这个XlFileFormat Enumeration (Excel)有可用的值,但我不确定哪一个是我需要的.

有用提示:如果有人尝试转换第一行中第一项的csv是ID,则会发生错误.将ID更改为id,它会没问题,更多信息SYLK: File format is not valid.

总结

以上是生活随笔为你收集整理的python保存为xlsb_如何使用Python将csv文件转换为xlsb?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。