简体   繁体   English

在python中使用Win32com在工作簿中插入行不起作用

[英]Inserting rows in workbook using win32com in python not working

I have a very specific question. 我有一个非常具体的问题。 The line: 该行:

expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert

in the code below is not working: 在下面的代码不起作用:

# Write data in expenses form
expform_wb = xl.Workbooks.Open(expform_path, Editable=True)
expform_ws = expform_wb.Worksheets('Expense Form')
last_row_ef = expense_items + 15

expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert
expform_ws.Range('Casecode').Value = case_code
expform_ws.Range('D6').Value = name
expform_ws.Range('D7').Value = last_name
expform_ws.Range('D8').Value = datetime.date.today().strftime("%d/%m/%Y")
expform_ws.Range('B16:B' + str(last_row_ef)).Value = date
expform_ws.Range('D16:D' + str(last_row_ef)).Value = descr

In case this helps: the line gets highlighted in PyCharm as "Statement seems to have no effect". 如果有帮助,则该行在PyCharm中突出显示为“声明似乎无效”。

Anyone can help to spot what I am doing wrong? 任何人都可以帮助发现我在做什么错?

Thanks! 谢谢!

In this line 在这条线

expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert

You aren't actually CALLING the function, you are just getting "reference" to it, add () to call it 您实际上不是在调用该函数,而只是在获取它的“引用”,添加()来调用它

expform_ws.Range("Total").Offset(-1, 0).EntireRow.Insert()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM