使用Python将文本文件embedded到excel中
我正在尝试使用Python将文本文件embedded到Excel中:
xl = win32.Dispatch('Excel.Application') xl.Visible = 1 wb = xl.Workbooks.Open("C:\inventory\INVENTORY.xls") column = wb.ActiveSheet.Range("D2:D200") i = 2 for cell in column: hostname_cell = wb.ActiveSheet.Cells(i,1).Value filename = 'C:\ioe\\' + str(hostname_cell) + '.txt' if hostname_cell is not None: print filename xl.ActiveSheet.OLEObjects().Add(FileName=filename, Link=False, DisplayAsIcon=True).Select i += 1
但是我得到这个错误:
TypeError: Add() got an unexpected keyword argument 'FileName'
我在网上search,但不明白为什么,有什么想法?
编辑:我得到同样的错误,如果我改变代码:
f = 'C:\ioe\\' + str(hostname_cell) + '.txt' if hostname_cell is not None: print f xl.ActiveSheet.OLEObjects().Add(FileName=f, Link=False, DisplayAsIcon=True).Select i += 1
要么
if hostname_cell is not None: print f xl.ActiveSheet.OLEObjects().Add(FileName='C:\Users\\robertph\Share\ioe\\' + str(hostname_cell) + '.txt', Link=False, DisplayAsIcon=True).Select i += 1