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.
-
Yes, there is. What have you tried so far?– Charlie ClarkCommented Jul 7, 2021 at 8:28
-
Honestly, I have tried to many things to remember.– RichardCommented 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– RichardCommented Jul 12, 2021 at 13:01
Add a comment
|
1 Answer
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)