How to Set Print Area with Python.NET
Contents
[
Hide
]
Possible Usage Scenarios
Setting a print area in a document helps control printed content. Key reasons include:
- Focus on Specific Data: Print only relevant sections
- Improved Layout: Organize content neatly across pages
- Save Resources: Reduce paper/ink consumption
- Professional Presentation: Ensure polished output
- Consistency: Maintain uniform print outputs
How to Set Print Area in Excel
To set a print area programmatically:
- Access worksheet’s page setup properties
- Define print area using cell range notation
- Save modified workbook
# Sample image reference remains unchanged
<img src="3.png" width=60% />
How to Clear Print Area in Excel
To remove print area constraints:
- Access page setup properties
- Reset print area to empty string
- Save changes
# Sample image reference remains unchanged
<img src="4.png" width=60% />
What Happens After Clearing the Print Area
Clearing the print area results in:
- Default printing of entire worksheet
- Removal of previous range constraints
- Inclusion of all formatted cells
How to Set Print Area Using Aspose.Cells
Set print area through worksheet’s page setup:
import aspose.cells as ac
# Load sample workbook
workbook = ac.Workbook("input.xlsx")
# Access first worksheet
worksheet = workbook.worksheets[0]
# Set print area to A1:D10
worksheet.page_setup.print_area = "A1:D10"
# Save modified workbook
workbook.save("output_set_print_area.xlsx")
# Output image reference
<img src="1.png" width=60% />
How to Clear Print Area Using Aspose.Cells
Remove existing print area definition:
import aspose.cells as ac
# Load sample workbook
workbook = ac.Workbook("input.xlsx")
# Access first worksheet
worksheet = workbook.worksheets[0]
# Clear print area
worksheet.page_setup.print_area = ""
# Save modified workbook
workbook.save("output_clear_print_area.xlsx")
# Output image reference
<img src="2.png" width=60% />
from aspose.cells import Workbook
# Load the workbook
workbook = Workbook("input.xlsx")
# Access the desired worksheet
worksheet = workbook.worksheets[0]
# Set the print area - specify the range you want to print
worksheet.page_setup.print_area = "A1:D10"
# Save the workbook
workbook.save("set_print_area.pdf")
from aspose.cells import Workbook
# Load the workbook
workbook = Workbook("input.xlsx")
# Access the desired worksheet
worksheet = workbook.worksheets[0]
# Clear the print area
worksheet.page_setup.print_area = ""
# Save the workbook
workbook.save("clear_print_area.pdf")