Impostazione dei margini
Come impostare i margini
Aspose.Cells per Python via .NET fornisce una classe, Workbook, che rappresenta un file Excel. La classe Workbook contiene la collezione worksheets che consente l’accesso a ogni foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato dalla classe Worksheet.
La classe Worksheet fornisce la proprietà page_setup utilizzata per impostare le opzioni di configurazione della pagina per un foglio di lavoro. L’attributo page_setup è un oggetto della classe PageSetup che consente agli sviluppatori di impostare diverse opzioni di layout di pagina per un foglio di lavoro stampato. La classe PageSetup fornisce varie proprietà e metodi utilizzati per impostare le opzioni di configurazione della pagina.
Come impostare i margini di pagina
Imposta i margini della pagina (sinistro, destro, superiore, inferiore) utilizzando i membri della classe PageSetup. Di seguito sono elencati alcuni dei metodi utilizzati per specificare i margini della pagina:
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a workbook object | |
workbook = Workbook() | |
# Get the worksheets in the workbook | |
worksheets = workbook.worksheets | |
# Get the first (default) worksheet | |
worksheet = worksheets[0] | |
# Get the pagesetup object | |
pageSetup = worksheet.page_setup | |
# Set bottom,left,right and top page margins | |
pageSetup.bottom_margin = 2.0 | |
pageSetup.left_margin = 1.0 | |
pageSetup.right_margin = 1.0 | |
pageSetup.top_margin = 3.0 | |
# Save the Workbook. | |
workbook.save(dataDir + "SetMargins_out.xls") |
Come centrare sulla pagina
È possibile centrare qualcosa su una pagina orizzontalmente e verticalmente. A tal scopo, ci sono alcuni membri utili della classe PageSetup, center_horizontally e center_vertically.
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create a workbook object | |
workbook = Workbook() | |
# Get the worksheets in the workbook | |
worksheets = workbook.worksheets | |
# Get the first (default) worksheet | |
worksheet = worksheets[0] | |
# Get the pagesetup object | |
pageSetup = worksheet.page_setup | |
# Specify Center on page Horizontally and Vertically | |
pageSetup.center_horizontally = True | |
pageSetup.center_vertically = True | |
# Save the Workbook. | |
workbook.save(dataDir + "CenterOnPage_out.xls") |
Come impostare i margini di intestazione e piè di pagina
Imposta i margini dell’intestazione e del piè di pagina con i membri della classe PageSetup come header_margin e footer_margin.