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

Is it possible to copy a particular sheet? If possible, how will I do it? #123

Closed
juniusfree opened this issue Dec 18, 2014 · 16 comments · Fixed by #1497
Closed

Is it possible to copy a particular sheet? If possible, how will I do it? #123

juniusfree opened this issue Dec 18, 2014 · 16 comments · Fixed by #1497
Milestone

Comments

@juniusfree
Copy link

No description provided.

@fzumstein
Copy link
Member

Currently not yet, but I will add this as a feature request. If you are on Windows and want to work around for now, you can do Sheet(1).xl_sheet.Copy(Before=Sheet(1).xl_sheet). But the After keyword is broken in pywin32, so if you need this, you'd have to wait until it's implemented.

@fzumstein fzumstein added this to the v0.3.1 milestone Dec 18, 2014
@juniusfree
Copy link
Author

Ok thanks! love to see it in the future releases.

@fzumstein fzumstein modified the milestones: v0.3.1, v0.3.2, v0.3.3, v0.3.4 Jan 16, 2015
@fzumstein fzumstein modified the milestone: v0.3.4 Mar 9, 2015
@bersanri
Copy link

bersanri commented Aug 7, 2015

Hi!
I'm just writing you to know if this issue has been solved.

@fzumstein
Copy link
Member

Nope, the status is on the top left - still open...

@fedterzi
Copy link

fedterzi commented Apr 26, 2017

Using v0.10.4 I had to replace xl_sheet with api: Sheet(1).api.Copy(Before=Sheet(1).api)

@Elijas
Copy link

Elijas commented Nov 1, 2017

If you want to copy a sheet to the end - the workaround for the broken After keyword is broken in pywin32 is to create a temporary sheet at the end using the native xlwings sheet.add, then copy a sheet Before the newly created sheet and finally delete the newly created sheet.

@bobjoylove
Copy link

bobjoylove commented Jul 30, 2018

sht.api.Copy() is not in V0.11 and we have no way to copy a sheet :(

@fzumstein
Copy link
Member

In the more recent versions of xlwings, here's an example of how to work around it:

import xlwings as xw
wb = xw.books.active
sht = wb.sheets['Sheet1']
sht.api.Copy(Before=sht.api)

@bobjoylove
Copy link

bobjoylove commented Aug 1, 2018

import xlwings as xw
wb = xw.books.active
sht = wb.sheets['Sheet1']
sht.api.Copy(Before=sht.api)
raise AttributeError("Unknown property, element or command: {!r}".format(name)) from e

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

Options alphabetically at sht.api. are beginswith(operand), contains(operand) and doesnotbeginwith(operand)
Notes: fresh install at 0.11 using pip install xlwings. Do I need to install the api somehow?

@manobeeslaar
Copy link

Hi there,

Is there a work around for MAC? To copy a sheet from one workbook to another workbook?

Thank you,

@fzumstein
Copy link
Member

fzumstein commented Aug 28, 2019

On macOS, this is how it works:

import xlwings as xw

wb = xw.books.active
sht_api = wb.sheets[0].api
sht_api.copy_worksheet(before_=sht_api)

@manobeeslaar
Copy link

Thank you!

@fzumstein fzumstein added this to the 0.20.1 milestone Jul 31, 2020
@fzumstein fzumstein removed this from the 0.20.1 milestone Aug 7, 2020
@fzumstein fzumstein modified the milestones: 0.20.3, 0.20.4, 0.20.5 Aug 13, 2020
@fzumstein fzumstein modified the milestones: 0.20.5, 0.20.6, 0.20.7 Aug 27, 2020
@fzumstein fzumstein modified the milestones: 0.20.7, 0.20.8 Sep 3, 2020
@fzumstein fzumstein modified the milestones: 0.20.8, 0.20.9 Oct 13, 2020
@fzumstein fzumstein modified the milestones: 0.20.9, 0.20.10 Nov 1, 2020
@fzumstein fzumstein modified the milestones: 0.21.1, 0.21.2, 0.21.3 Nov 8, 2020
@mullimanko
Copy link

@fzumstein, I can't retrace what you wrote in your first post that After keyword is broken in pywin32. See: https://stackoverflow.com/questions/64820928/move-worksheet-within-a-workbook-to-the-end/64837195#64837195

@fzumstein
Copy link
Member

@mullimanko gotcha, thanks for your note!

@fzumstein fzumstein modified the milestones: 0.21.3, 0.21.4, 0.21.5 Nov 22, 2020
@ffisc
Copy link

ffisc commented Jan 25, 2021

Here you go:

import xlwings as xw

wb = xw.books.active
sht_api = wb.sheets[0].api
sht_api.copy_worksheet(before_=sht_api)

Hi, has the API changes by any chance? I'm trying this and getting

File "C:\Users\xxx\Anaconda3\lib\site-packages\xlwings\_xlwindows.py", line 141, in __getattr__
    self._oleobj_.GetIDsOfNames(0, item)
pywintypes.com_error: (-2147352570, 'Unknown name.', None, None)

@fzumstein
Copy link
Member

@ffisc that's the macOS version, if you are on Windows, do: #123 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants