Skip to content
GitLab
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 264
    • Issues 264
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • openpyxl
  • openpyxl
  • Issues
  • #1821
Closed
Open
Issue created May 04, 2022 by Pietro Acinapura@raymanzarek1984

Cannot add multiple sort conditions

I'm trying to add multiple sort conditions to a worksheet. The file is correctly saved but an error is displayed by Excel while opening it.

Example:

from random import randrange
from openpyxl import Workbook

wb = Workbook()
ws = wb.active

data = [
    ["Fruit", "Quantity", "Price"],
    ["Kiwi", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Grape", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Apple", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Peach", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Pomegranate", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Pear", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Tangerine", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Blueberry", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Mango", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Watermelon", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Blackberry", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Orange", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Raspberry", randrange(0, 10, 1), randrange(1, 100, 1)],
    ["Banana", randrange(0, 10, 1), randrange(1, 100, 1)]
]

for r in data:
     ws.append(r)

ws.auto_filter.ref = "A1:C15"
ws.auto_filter.add_sort_condition("B2:B15", descending=True)
ws.auto_filter.add_sort_condition("C2:C15")

wb.save("filtered.xlsx")
Edited May 08, 2022 by CharlieC
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking