如何使用python将XLSB文件转换为csv? [英] How can I convert a XLSB file to csv using python?

查看:345
本文介绍了如何使用python将XLSB文件转换为csv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已为我提供了一个充满数据的xlsb文件.我想使用python处理数据.我可以使用excel或开放式办公室将其转换为csv,但我希望整个过程更加自动化.有任何想法吗?

更新:我查看了这个问题,并使用第一个答案:

import subprocess
subprocess.call("cscript XlsToCsv.vbs data.xlsb data.csv", shell=False)

问题是文件包含希腊字母,因此未保留编码.使用Notepad ++打开csv看起来应该是正确的,但是当我尝试插入数据库时​​会出现这样的情况.以csv格式打开文件,只是为了读取文本,显示如下: \ xc2 \ xc5 \ xcb而不是ΒΕΛ.

我意识到这是编码方面的问题,但是可以保留将xlsb文件转换为csv的原始编码?

解决方案

最受欢迎的Excel python软件包 openpyxl xlrd 不支持xlsb格式(错误跟踪器条目:将XLS编程转换为XLSB吗?.您在标题中提到了python,但问题并不表示您与它紧密相关,因此可以采用纯c#方式.

如果您仅对python感到非常自在,则建议使用名称为 subprocess 将其作为python中的外部工具编写脚本.. >

我知道这不是一个很好的答案,但是我认为目前为止没有更好/更简便的方法.

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)

The issue is the file contains greek letters so the encoding is not preserved. Opening the csv with Notepad++ it looks as it should, but when I try to insert into a database comes like this ���. Opening the file as csv, just to read text is displayed like this: \xc2\xc5\xcb instead of ΒΕΛ.

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

解决方案

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.

这篇关于如何使用python将XLSB文件转换为csv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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