Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openpyxl
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 235
    • Issues 235
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • openpyxl
  • openpyxl
  • Issues
  • #698

Closed
Open
Created Oct 18, 2016 by Bitbucket Importer@bitbucket_importerOwner

The copy of a Comment should return a detached clone

Created originally on Bitbucket by Tantale (Laurent LAPORTE)

It is impossible to copy a comment from a source cell to a destination cell because the copy of the comment is still attached with the source.

The following unit test fails:

def test_copy():
    wb = Workbook()
    ws = Worksheet(wb)
    source = Comment("text", "author")
    ws.cell(row=1, column=1).comment = source

    clone = copy(source)
    ws.cell(row=2, column=1).comment = clone
    assert clone._parent == ws.cell(row=2, column=1)
    assert clone.text == "text"
    assert clone.author == "author"

With the error: "AttributeError: Comment already assigned to A2 in worksheet Sheet1. Cannot assign a comment to more than one cell"

The solution is to implement the __copy__ operator for openpyxl.comments.comments.Comment class:

def __copy__(self):
    """Create a detached copy of this comment."""
    clone = self.__class__(self.content, self.author)
    clone.width = self.width
    clone.height = self.height
    return clone
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking