简体   繁体   中英

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".

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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