The DisplayFullScreen property of the Application object in Excel is a Boolean value that controls whether the Excel application window is displayed in full-screen mode. When set to True, Excel maximizes the window to occupy the entire screen, hiding elements such as the ribbon, formula bar, and status bar to provide a larger workspace for viewing or presenting data. This can be particularly useful for creating distraction-free dashboards, presentations, or when working with large datasets that require maximum screen real estate. Conversely, setting it to False restores the normal window view with all interface elements visible.
In xlwings, this property is accessed through the app object, which represents the Excel application. The syntax for getting or setting the DisplayFullScreen property is straightforward, as it behaves like a standard property in Python.
Syntax:
- Get the current state:
app.api.DisplayFullScreen - Set to full-screen mode:
app.api.DisplayFullScreen = True - Exit full-screen mode:
app.api.DisplayFullScreen = False
Parameters:
- There are no explicit parameters for this property; it is a simple Boolean attribute. The value can be either
True(to enable full-screen) orFalse(to disable it).
Example Usage:
Here are a few practical examples demonstrating how to use the DisplayFullScreen property with xlwings:
- Enabling Full-Screen Mode:
This code snippet launches Excel, opens a workbook, and switches to full-screen mode.
import xlwings as xw
app = xw.App(visible=True)
workbook = app.books.open('example.xlsx')
app.api.DisplayFullScreen = True
- Toggling Full-Screen Mode:
This example shows how to check the current state and toggle it based on user input or a condition.
import xlwings as xw
app = xw.App(visible=True)
workbook = app.books.add()
# Check if currently in full-screen
if app.api.DisplayFullScreen:
print("Currently in full-screen mode. Exiting...")
app.api.DisplayFullScreen = False
else:
print("Switching to full-screen mode...")
app.api.DisplayFullScreen = True
- Disabling Full-Screen on Workbook Close:
This ensures that full-screen mode is turned off when closing the workbook, restoring the normal Excel interface.
import xlwings as xw
app = xw.App(visible=True)
workbook = app.books.open('data.xlsx')
app.api.DisplayFullScreen = True
# Perform some operations...
workbook.save()
app.api.DisplayFullScreen = False # Exit full-screen before closing
workbook.close()
app.quit()
Leave a Reply