Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete one row or column? #862

Closed
reaCodes opened this issue May 5, 2018 · 9 comments · Fixed by #1212
Closed

How to delete one row or column? #862

reaCodes opened this issue May 5, 2018 · 9 comments · Fixed by #1212
Labels
Milestone

Comments

@reaCodes
Copy link

@reaCodes reaCodes commented May 5, 2018

If I want to delete the first row, I can use Sheet1.Rows(1).Delete in VBA
or Using Sheet1.Columns(1).Delete to delete the first column.

How to achieve the same effect through it?

@gwdekker

This comment has been minimized.

Copy link

@gwdekker gwdekker commented May 7, 2018

Supported trhough the api functionality:

import xlwings as xw
from xlwings import constants
xw.Range("A:A").api.Delete(constants.DeleteShiftDirection.xlShiftUp)
@reaCodes

This comment has been minimized.

Copy link
Author

@reaCodes reaCodes commented May 7, 2018

@gwdekker It works. But this kind of solution is a bit complicated. Is there a clear and concise way?

@reaCodes

This comment has been minimized.

Copy link
Author

@reaCodes reaCodes commented May 7, 2018

import xlwings as xw 

wb = xw.Book('c:\\users\\zhong\\downloads\\test.xlsx')
sht = wb.sheets[0]
sht.range('A:A').api.Delete()

This can also works.
What functions does .api. have?

@fzumstein

This comment has been minimized.

@gwdekker

This comment has been minimized.

Copy link

@gwdekker gwdekker commented May 7, 2018

In practice I found that the MS dev pages give a good idea on the available functionality through the win32 api, for example https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-delete-method-excel.
another good page is https://github.com/pybokeh/jupyter_notebooks/blob/master/xlwings/Excel_Formatting.ipynb with a lot of the most common missing features addressed.

@jwilly1127

This comment has been minimized.

Copy link

@jwilly1127 jwilly1127 commented Jul 9, 2018

This returns an error
selectortype, code = self.AS_appdata.referencebyname()[name]
KeyError: 'Delete'

The above exception was the direct cause of the following exception:

raise AttributeError("Unknown property, element or command: {!r}".format(name)) from e

AttributeError: Unknown property, element or command: 'Delete'

@fzumstein

This comment has been minimized.

Copy link
Member

@fzumstein fzumstein commented Jul 9, 2018

@jwilly1127 for the mac version you'll need to use: sht.range('A:A').api.delete() (lower case)

@a346145380

This comment has been minimized.

Copy link

@a346145380 a346145380 commented Feb 14, 2019

hey, Felix.
Do you consider include range(??).clear() type of functionality? I think it would be very useful. pywin32 documentation is not very helpful.

e.g. wb.sheets['x'].range("B17").expand("table").api.ClearContents()

@fzumstein

This comment has been minimized.

Copy link
Member

@fzumstein fzumstein commented Feb 14, 2019

clear_contents is available, see https://docs.xlwings.org/en/stable/api.html

In the future, please open a seperate issue instead of hijacking a different issue.

@fzumstein fzumstein added this to the 0.16.4 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.