Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python xlwings包错误:OSError:[WinError-2147467259]未指定错误_Python_Python 3.x_Pandas_Xlwings - Fatal编程技术网

python xlwings包错误:OSError:[WinError-2147467259]未指定错误

python xlwings包错误:OSError:[WinError-2147467259]未指定错误,python,python-3.x,pandas,xlwings,Python,Python 3.x,Pandas,Xlwings,我正在尝试使用xlwings包将Python数据帧写入.xlsm文件。我的代码有时工作正常,但有时会失败并抛出: OSError:[WinError-2147467259]未指定错误 示例代码: import xlwings as xw import pandas as pd import numpy as np app = xw.App(visible=False) filename="test.xlsm" book = xw.Book(filename) sht = bo

我正在尝试使用xlwings包将Python数据帧写入
.xlsm
文件。我的代码有时工作正常,但有时会失败并抛出:

OSError:[WinError-2147467259]未指定错误

示例代码:

import xlwings as xw
import pandas as pd
import numpy as np
app = xw.App(visible=False)
filename="test.xlsm"
book = xw.Book(filename)
sht = book.sheets("ASSET")
#asset_df ,asset_spec_df are the  data-frame (i get this data-frame value from another function)
sht.range('B9').options(index=False, header=False).value = asset_df
sht=book.sheets("ASSETSPEC")
sht.range('B9').options(index=False, header=False).value = asset_spec_df
book.save()
book.close()
app.quit()
 book = xw.Book(filename) --- error line

  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\main.py", line 514, in __init__
    for wb in app.books:
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\main.py", line 368, in books
    return Books(impl=self.impl.books)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 392, in books
    return Books(xl=self.xl.Workbooks)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 313, in xl
    self._xl = get_xl_app_from_hwnd(self._hwnd)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 223, in get_xl_app_from_hwnd
    ptr = accessible_object_from_window(child_hwnd)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 191, in accessible_object_from_window
    res = oledll.oleacc.AccessibleObjectFromWindow(
  File "_ctypes/callproc.c", line 948, in GetResult
OSError: [WinError -2147467259] Unspecified error
此代码有时会正常工作,但有时会抛出以下错误:

错误:

import xlwings as xw
import pandas as pd
import numpy as np
app = xw.App(visible=False)
filename="test.xlsm"
book = xw.Book(filename)
sht = book.sheets("ASSET")
#asset_df ,asset_spec_df are the  data-frame (i get this data-frame value from another function)
sht.range('B9').options(index=False, header=False).value = asset_df
sht=book.sheets("ASSETSPEC")
sht.range('B9').options(index=False, header=False).value = asset_spec_df
book.save()
book.close()
app.quit()
 book = xw.Book(filename) --- error line

  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\main.py", line 514, in __init__
    for wb in app.books:
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\main.py", line 368, in books
    return Books(impl=self.impl.books)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 392, in books
    return Books(xl=self.xl.Workbooks)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 313, in xl
    self._xl = get_xl_app_from_hwnd(self._hwnd)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 223, in get_xl_app_from_hwnd
    ptr = accessible_object_from_window(child_hwnd)
  File "C:\Users\prabhaahar.nagesh\AppData\Roaming\Python\Python38\site-packages\xlwings\_xlwindows.py", line 191, in accessible_object_from_window
    res = oledll.oleacc.AccessibleObjectFromWindow(
  File "_ctypes/callproc.c", line 948, in GetResult
OSError: [WinError -2147467259] Unspecified error

如注释中所述,如果一次在多个实例中打开同一本书(aka.
.xlsm
),应用程序将抛出错误

检查您现在尝试运行的应用程序是否已经在后台运行。如果是,请关闭这些活动应用程序并重新运行


下面是有关该问题的更多信息->

如注释中所述,如果一次在多个实例中打开同一本书(aka.
.xlsm
),应用程序将抛出错误

检查您现在尝试运行的应用程序是否已经在后台运行。如果是,请关闭这些活动应用程序并重新运行


以下是有关此问题的详细信息->

如果在多个实例中打开同一本书(aka.
.xlsm
),应用程序将抛出错误。如果在多个实例中打开同一本书(aka.
.xlsm
),应用程序将抛出一个错误。在运行该代码之前,我已从任务管理器关闭了所有打开的.xlsm Excel实例,问题仍然存在。不是
.xlsm
,而是后台运行的使用.xlsm读取数据的python程序。如果重新启动计算机并在运行上述python程序后立即运行,则不会出现问题。在运行该代码之前,我已从任务管理器关闭了所有打开的.xlsm Excel实例,问题仍然存在。不是
.xlsm
,而是后台运行的python程序使用.xlsm读取数据。如果重新启动计算机并在运行上述python程序后立即运行,则该程序将正常工作。