xlwings - Delete a range of rows

寵の児 提交于 2019-12-12 10:04:05

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/38873058/xlwings-delete-a-range-of-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!