1

When creating a new spreadsheet using openpyxl, the first time the new spreadsheet is opened in Excel, it appears full-screen, completely filling the display. How can I set the geometry of the window, either in terms of columns and rows, or screen location and window dimensions, so that it opens in a smaller window.

3
  • Yes, there is. What have you tried so far? Commented Jul 7, 2021 at 8:28
  • Honestly, I have tried to many things to remember.
    – Richard
    Commented Jul 7, 2021 at 13:02
  • I have found something potentially useful (BookView). But, it does notjing. view = BookView(activeTab=0, windowHeight=400, windowWidth=500, showSheetTabs=False) ws.bookViews = view
    – Richard
    Commented Jul 12, 2021 at 13:01

1 Answer 1

1

BookView is the right class. The problem is how to call it and set the view.

from openpyxl.workbook.views import BookView
...
    wb = openpyxl.Workbook()
    view = [BookView(xWindow=0, yWindow=0, windowWidth=18140, windowHeight=15540)]
    wb.views = view

For the definition of: xWindow, yWindow, windowWidth, windowHeight and more, see the MS Excell documentation Note, the values are in twips (1/20 of a point)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.