可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

I have been provided with a xlsb file full of data. I want to process the data using python. I can convert it to csv using excel or open office, but I would like the whole process to be more automated. Any ideas?

Update: I took a look at this question and used the first answer: import subprocess subprocess.call("cscript XlsToCsv.vbs data.xlsb data.csv", shell=False)

I realize it's an issue in encoding, but it's possible to retain the original encoding converting the xlsb file to csv ?

回答1:

Most popular Excel python packages openpyxl and xlrd have no support for xlsb format (bug tracker entries: openpyxl, xlrd).

So I'm afraid there is no native python way =/. However, since you are using windows, it should be easy to script the task with external tools.

I would suggest taking look at Convert XLS to XLSB Programatically?. You mention python in title but the matter of the question does not imply you are strongly coupled to it, so you could go pure c# way.

If you feel really comfortable only with python one of the answers there suggests a command line tool under a fancy name of Convert-XLSB. You could script it as an external tool from python with subprocess.

I know this is not a good answer, but I don't think there is better/easier way as of now.

回答2:

I also looked at the problem and the following worked for me. First opening the file in excel via python and than saving it to different file. Bit of a workaround but I like it more than other solutions. In example I use file format 6 which is CSV but you can also use other ones. import win32com.client excel = win32com.client.Dispatch("Excel.Application") excel.DisplayAlerts = False excel.Visible=False doc = excel.Workbooks.Open("C:/users/A295998/Python/@TA1PROG3.xlsb") doc.SaveAs(Filename="C:\\users\\A295998\\Python\\test5.csv",FileFormat=6) doc.Close() excel.Quit()

回答3:

I've encountered this same problem and using pyxlsb does it for me: from pyxlsb import open_workbook with open_workbook('HugeDataFile.xlsb') as wb: for sheetname in wb.sheets: with wb.get_sheet(sheetname) as sheet: for row in sheet.rows(): values = [r.v for r in row] # retrieving content csv_line = ','.join(values) # or do your thing

回答4:

In my previous experience, i was handling converting xlsb using libreoffice command line utility,

In ruby i just execute system command to call libreoffice for converting xlsb format to csv: `libreoffice --headless --convert-to csv your_csv_file.csv --outdir /path/csv`

and to change the encoding i use command line to using iconv, using ruby : `iconv -f ISO-8859-1 -t UTF-8 your_csv_file.csv > new_file_csv.csv`

回答5:

XLSB is a binary format and I don't think you'll be able to parse it with current python tools and packages. If you still want to somehow automate the process with python you can do what the others have told you and script that windows CLI tool. Calling the .exe from the command line with subprocess, and passing an array of the files you want to convert.

I.e: with a script similar to this one you could convert all the .xlsb files that you place in the "xlsb" folder to .csv format...

xlsb_to_csv.py #!/usr/bin/env python import os files = [f for f in os.listdir('./xlsb')] for f in files: subprocess.call("ConvertXLS.EXE " + str(f) + " --arguments", shell=True)

Note: the Windows command is pseudocode... I use a similar approach to batch-convert stuff in headless windows servers for testing purpouses. You just have to figure out the exe location and the windows command...

Hope it helps... good luck!

回答6:

I think you can do this using pyuno. This blog entry shows how to convert xls files to csv, and as open office supports xlsb files since version 3.2, this code might just work for you. You will have to go through hassle of setting up the pyuno environment though..

回答7:

The script you reference seem to use the ActiveX interface to Excel, and save via its Workbook.SaveAs method. According to the MSDN documentation this method have a TextCodepage argument which may be helpful.

Sidenote: You can rewrite the VB script in python, see this question.

python保存为xlsb_How can I convert a XLSB file to csv using python?相关推荐

  1. python保存文件到桌面_将文件从列表拖到桌面python

    奇怪的是,它说AddFile方法在文档中只是Windows,但是我不知道这是否真的是真的.总之,下面是一个简单的例子,基于您给出的原始示例:import wx import os import tim ...

  2. python保存为xlsb_Python XLSB到CSV的转换数据类型

    我一直致力于创建一个脚本,将Excel文件转换成csv,以便在我们的一些工具中进行进一步处理.在 对于xls.xlsx和xlsm,我找到了将文件作为文本对象打开或使用pandas的解决方案.当遇到xl ...

  3. python保存requests请求的文件的实战代码

      大家好,我是爱编程的喵喵.双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中.从事机器学习以及相关的前后端开发工作.曾在阿里云.科大讯飞.CCF等比赛获得多次Top名次.现 ...

  4. Nvidia Deepstream小细节系列:Deepstream python保存pipeline结构图

    Nvidia Deepstream小细节系列:Deepstream python保存pipeline结构图 提示:此章节我们将着重阐述如何在Deepstream Python运行的情况下保存pipel ...

  5. python 保存内容到记事本里面

    python 保存内容到记事本里面 使用函数open 模式设置为,没有记事本的时候创建记事本即可, 代码很简单如下 def writeTxt():file = open(r"C:\text. ...

  6. python保存大列表(list)数据到文件并后续重新加载为列表(list)对象实战

    python保存大列表(list)数据到文件并后续重新加载为列表(list)对象实战 笔者遇到的问题是这样的, 在做机器学习模型的时候,有的时候会使用相关性分析的方法来进行特征的筛选,去除冗余特征,降 ...

  7. python保存内容到文件(text、json、csv)

    python保存内容到文件(text.json.csv) 在开发人员的日常中,将数据保存到文件是最常见的编程任务之一. 通常,程序需要一些输入并产生一些输出.在许多情况下,我们希望将这些结果持久化.我 ...

  8. 解决python 保存json到文件时 中文显示16进制编码的问题

    解决python 保存json到文件时 中文显示16进制编码的问题 参考文章: (1)解决python 保存json到文件时 中文显示16进制编码的问题 (2)https://www.cnblogs. ...

  9. linux python保存mp4

    解决 python调用OpenCV 保存视频时使用"avc1"格式出现# Could not find encoder for codec id 27: Encoder not f ...

最新文章

  1. 网页中添加QQ,msn留言按钮
  2. 根据awr报告查看最慢的sql语句
  3. android lk DEFINES定义的环境变量的值
  4. Entity Framework系列之DataBase First
  5. shell之a+b求和l脚本的三种写法
  6. smp架构与numa架构_NUMA架构和Java
  7. python列表各元素修改为int类型
  8. keil uVision4 创建项目
  9. gulp + angular + requirejs 简单学习
  10. 设计模式之抽象状态模式
  11. qdir 类似工具_实用工具——多窗口资源管理器qdir
  12. google linux桌面快捷方式,centos7 rhel7 linux下怎么安装google chrome 设置谷歌浏览器桌面快捷方式...
  13. 主动微波遥感的测量原理
  14. 自己制作并发布720°VR全景图
  15. 分布式机器学习平台比较
  16. python猴子分桃问题_阶乘
  17. 面试官最容易提出的20个问题
  18. *新手看php手册的正确姿势
  19. 常见的字体英文名称(转载内容)
  20. 让电代替人工去计算——机电时期的权宜之计

热门文章

  1. Java读取Excel中的图片,并保存
  2. 银行股从“宽货币”到“宽信用”的传导 中富金石老师建议“持股过年”
  3. 百度网盘超级加倍下载
  4. linux一键脚本自动添加Title
  5. ipad无法充电怎么办_ipad不能充电怎么办 ipad不能充电解决方法【图文】
  6. linux 最牛机器,最牛B的 Linux Shell 命令(二)
  7. dayjs 获取上个月的今天
  8. ffserver + hls
  9. 马云:阿里巴巴设七个分公司是因为讲究风水
  10. linux跑pin软件下载,WPSApp Pro APP