Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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
VBA到Python的转换_Python_Excel_Vba_Pywin32 - Fatal编程技术网

VBA到Python的转换

VBA到Python的转换,python,excel,vba,pywin32,Python,Excel,Vba,Pywin32,我有一个vba宏,它在excel的D列中嵌入了一系列文本文件,该文件引用a列中的值,并在该列中进行迭代。 在将其转换为Python的过程中,我遇到了一个难题,即指定文件嵌入的位置。vba宏将每个文件嵌入到相关行中,而Python脚本以其当前形式将所有文件嵌入到同一单元格中(B2)。我尝试过各种策略,主要是在不同的地方放置补偿,但没有成功,也没有在网上找到任何例子。 以下是代码片段: VBA: Python: folder = 'C:\Users\ioe\\' #raw_input("Please

我有一个vba宏,它在excel的D列中嵌入了一系列文本文件,该文件引用a列中的值,并在该列中进行迭代。 在将其转换为Python的过程中,我遇到了一个难题,即指定文件嵌入的位置。vba宏将每个文件嵌入到相关行中,而Python脚本以其当前形式将所有文件嵌入到同一单元格中(B2)。我尝试过各种策略,主要是在不同的地方放置补偿,但没有成功,也没有在网上找到任何例子。 以下是代码片段: VBA:

Python:

folder = 'C:\Users\ioe\\' #raw_input("Please specify Show Files directory: ")
inventory_csv = 'inventory.csv'
book = Workbook()
sheet = book.add_sheet('Inventory',cell_overwrite_ok=True)

inventory_data_to_csvfile(folder)

csv_to_xls(inventory_csv)

os.remove('inventory.csv')

xl = win32.gencache.EnsureDispatch('Excel.Application')
xl.Visible = 1
wb = xl.Workbooks.Open("C:\Users\\robertph\Share\inventory\INVENTORY.xls")

column = wb.ActiveSheet.Range("A2:A200")
for cell in column:
    if cell.Value is not None:
        f = 'C:\Users\\robertph\Share\ioe\\' + str(cell.Value) + '.txt'
        ol = wb.ActiveSheet.OLEObjects().Add(Filename=f, Link=False)
        #ol.Offset(0, 3)
        #cell.GetOffset(0, 3).Value = ol 
        #ol_offset = ol.Cells(cell).GetOffset(0, 3)
        #ol.Top = cell.Offset(0, 3)
        #ol.Left = cell.Offset(0, 3)

任何建议都将不胜感激。谢谢。

如果其他人发现自己处于同样的位置;我终于解决了:(呸!)

folder = 'C:\Users\ioe\\' #raw_input("Please specify Show Files directory: ")
inventory_csv = 'inventory.csv'
book = Workbook()
sheet = book.add_sheet('Inventory',cell_overwrite_ok=True)

inventory_data_to_csvfile(folder)

csv_to_xls(inventory_csv)

os.remove('inventory.csv')

xl = win32.gencache.EnsureDispatch('Excel.Application')
xl.Visible = 1
wb = xl.Workbooks.Open("C:\Users\\robertph\Share\inventory\INVENTORY.xls")

column = wb.ActiveSheet.Range("A2:A200")
for cell in column:
    if cell.Value is not None:
        f = 'C:\Users\\robertph\Share\ioe\\' + str(cell.Value) + '.txt'
        ol = wb.ActiveSheet.OLEObjects().Add(Filename=f, Link=False)
        #ol.Offset(0, 3)
        #cell.GetOffset(0, 3).Value = ol 
        #ol_offset = ol.Cells(cell).GetOffset(0, 3)
        #ol.Top = cell.Offset(0, 3)
        #ol.Left = cell.Offset(0, 3)
range = wb.ActiveSheet.Range("A2:A200")
for cell in range:
    if cell.Value is not None:
        f = 'C:\Users\\robertph\Share\ioe\\' + str(cell.Value) + '.txt'
        ol = wb.ActiveSheet.OLEObjects().Add(Filename=f, Link=False)
        ol.Top = cell.GetOffset(0, 3).Top
        ol.Left = cell.GetOffset(0, 3).Left