xlwings - Delete a range of rows

2019-05-25 04:26发布

I can't seem to find a way to be able to delete a range of rows starting at row x and going to the bottom of the sheet

For example in VBA code I would do

  Rows(CStr(currRow) & ":65536").Select
  Selection.Delete Shift:=xlUp

where currRow could be anything - i.e I don't necessarily want to delete everything from the sheet

Is there an equivalent in xlwings?

标签: xlwings
1条回答
何必那么认真
2楼-- · 2019-05-25 05:21

There's an open issue to take care of that. In the meantime, as usual, you can work around as explained in the docs.

In your case, something like the following should do (using v0.9 syntax):

import xlwings as xw
from xlwings.constants import DeleteShiftDirection

sht = xw.sheets.active
sht.range(str(currRow) + ':65536').api.Delete(DeleteShiftDirection.xlShiftUp)
查看更多
登录 后发表回答