xlwings UDF可以从文件读取吗?

时间:2018-08-23 06:18:40

标签: python excel-vba xlwings

我试图用相同代码的Python版本替换对Matlab的一些VBA调用,并且我将 xlwings 作为调用Python的方式。

一些Python代码如下所示:

mat_filename = 'G:\\My Shared Folder\\my_file.mat'
load_data = scipy.io.loadmat(mat_filename)

当我在调试模式下单步执行代码时,此方法工作正常,但是当我尝试在调试模式下运行代码 not 时,它会崩溃。我遇到这种错误:

TypeError:   'NoneType' object is not iterable
  byte_stream, file_opened = _open_file(file_name, appendmat)
File "C:\Users\lebala\AppData\Roaming\Python\Python35\site-packages\scipy\io\matlab\mio.py", line 64, in mat_reader_factory
  MR, file_opened = mat_reader_factory(file_name, appendmat, **kwargs)
File "C:\Users\lebala\AppData\Roaming\Python\Python35\site-packages\scipy\io\matlab\mio.py", line 141, in loadmat
  load_data = scipy.io.loadmat(mat_filename)
File "c:\users\lebala\repos\echelon\Echelon\generate_simulations.py", line 175, in generate_simulations
  return_protection_mean_return=return_protection_mean_return, return_warnings=return_warnings)
File "c:\users\lebala\repos\echelon\echelon_excel.py", line 40, in generate_simulations_excel
  ret = func(*args)
File "C:\Users\lebala\AppData\Roaming\Python\Python35\site-packages\xlwings\udfs.py", line 250, in call_udf
  Res = call_udf(Script, fname, args, this_workbook, FromVariant(Caller))
File "C:\Users\lebala\AppData\Roaming\Python\Python35\site-packages\xlwings\server.py", line 190, in CallUDF
  return func(*args)
File "C:\Program Files\Python35\lib\site-packages\win32com\server\policy.py", line 586, in _invokeex_
  return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Program Files\Python35\lib\site-packages\win32com\server\policy.py", line 283, in _invoke_
  return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Program Files\Python35\lib\site-packages\win32com\server\policy.py", line 278, in _Invoke_

当通过 xlwings 调用Python时,几乎就像Python不太擅长查找用于读取文件的路径。

还有其他人遇到此问题吗?有办法解决吗?

0 个答案:

没有答案