Richard
Richard

Reputation: 61

Set window size in Python openpyxl

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.

Upvotes: 1

Views: 499

Answers (1)

Richard
Richard

Reputation: 61

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)

Upvotes: 1

Related Questions