使用Go语言在OS X上解析Excel文件。

huangapple go评论93阅读模式
英文:

Parse Excel file using Go on OS X

问题

我正在尝试使用GoLang读取Excel文件(即使不是.xlsx格式),并使用几个库都无法成功。这些库在打开文件阶段会崩溃,并显示以下错误:

zip: not a valid zip file

我尝试使用的库有:
https://github.com/tealeg/xlsx
https://github.com/tealeg/xlsx2csv/

还有其他一些库,但它们在执行"go get Name-of-Lib"命令时由于某些DLL问题而崩溃。

有什么想法吗?这是因为我在MacOS下尝试还是其他原因?

英文:

I'm trying to read Excel file with GoLang (even not .xlsx) and by using several libraries can't have success in it. The libraries just crashes on OpenFile stage with such error:

zip: not a valid zip file

Libraries which I tried to use:
https://github.com/tealeg/xlsx
https://github.com/tealeg/xlsx2csv/

There were some others too, but they were crashed during

go get Name-of-Lib because of some Dll problems.

Any ideas? Is it because I'm trying to do in under MacOS or by some other reason?

答案1

得分: 4

你正在尝试使用的库12仅支持最新的Microsoft Excel格式,实际上是一个包含XML文档的zip文件。因此你会得到错误信息:zip: not a valid zip file。这些库可以在你的MacOS上使用,但首先你需要将旧的XLS文件转换为XLSX文件。你可以像其他问题中描述的那样,使用LibreOffice的无界面模式来进行转换,你可以从你的代码中运行一个进程。

其他的库出现"dll"错误,是因为它们必须链接到Windows动态链接库。因此,它们在你的MacOS上无法使用。

英文:

The libraries you are trying to use 1, 2 support only newest Microsoft Excel format which is actually a zip with xml documents. Therefore you get error: zip: not a valid zip file. Those can be used on your MacOS, but first you need to convert the old XLS files into XLSX files. You should be able to convert them with LibreOffice in headless mode like described other question, you can run a process from your code.

The other libraries are failing with "dll" errors because they must be linked against Windows Dynamic Link Libraries. As so, they are not usable on your MacOS.

huangapple
  • 本文由 发表于 2014年10月30日 05:51:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/26641289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定