本文介绍了在Iron Python中编写xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Iron Python(v2.7.5)中创建一个xlsx文件.
我已经安装了最新版本的openpyxl(v2.2.1),并测试了一个简单的示例,该示例几乎完全取自openpyxl文档:

I am trying to create an xlsx file in Iron Python (v2.7.5).
I have installed the latest version of openpyxl (v2.2.1) and tested a minimalistic example, almost literally taken from openpyxl documentation:

from openpyxl import Workbook
wb = Workbook()
wb.save('empty.xlsx')

我在CPython中正在按预期工作(创建一个空工作簿),但是在Iron Python中,它只是引发异常.

I is working as expected in CPython (creating an empty workbook), but in Iron Python it is just throwing exceptions.

  File "test_openpyxl.py", line 15, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\workbook\workbook.py", line 298, in save
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\writer\excel.py", line 196, in save_workbook
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\writer\excel.py", line 179, in save
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\writer\excel.py", line 67, in write_data
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\workbook\properties.py", line 103, in write_properties
  File "C:\Program Files (x86)\IronPython 2.7\lib\site-packages\openpyxl\utils\datetime.py", line 33, in datetime_to_W3CDTF

TypeError:预期的日期时间,获得了Object_1 $ 1

TypeError: expected datetime, got Object_1$1

我猜该错误是由某些.NET对象意外弹出引起的,但我对Object_1感到困惑,因此找不到它是什么对象.

I guess the error is caused by some .NET object popping unexpectedly, but I am confused by Object_1 thing, so could not find what object it was.

我还尝试了旧版本的软件包,只有使用v1.8.0时,我才能获得一些结果:

I have also tried older versions of the packages, and only with v1.8.0 I was able to get some results:

  • openpyxl-2.1.0毫无例外地运行(仅带有弃用警告),但是Excel抱怨所创建文件中的内容损坏.enter code here
  • openpyxl-2.0.5引发另一个异常(已经在这里报道)
  • openpyxl-1.8.6引发"ImportError:无法从openpyxl.styles导入PatternFill"
  • openpyxl-1.8.0打印出警告(UserWarning: Unable to import 'xml.etree.cElementree'. Falling back on 'xml.etree.Elementree'),这是经过合理考虑后得出的.因此,这可能是唯一可行的版本.
  • openpyxl-2.1.0 runs without exceptions (only with a deprecation warning), but Excel complains on corrupt content in the created file.enter code here
  • openpyxl-2.0.5 throws another exception (already reported here)
  • openpyxl-1.8.6 throws "ImportError: cannot import PatternFill from openpyxl.styles"
  • openpyxl-1.8.0 prints out a warning (UserWarning: Unable to import 'xml.etree.cElementree'. Falling back on 'xml.etree.Elementree'), which is after some thought is quite reasonable. So this is probably the only version that works.

在进一步探讨之前,我想问一下社区: 1.是否有人在IronPyth下成功使用openpyxl 2.是否还有其他可用的库,并且可以创建格式适中的xlsx文件?

Before I dig further, I wanted to ask the community: 1. Has anyone managed to use openpyxl under IronPyth 2. Are there any other libraries that work and that cancreate moderately formatted xlsx files?

推荐答案

我认为简短的答案是您不能在IronPython中使用openpyxl.我们使用描述符进行类型输入,IronPython似乎难以接受.

I think the short answer is that you can't use openpyxl with IronPython. We use descriptors for typing and IronPython seems to struggle with them.

这篇关于在Iron Python中编写xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 22:08