Impostazione dei margini

Impostazione margini

Aspose.Cells fornisce una classe, Workbook, che rappresenta un file di Excel. La classe Workbook contiene la raccolta Worksheets che consente di accedere a ciascun foglio di lavoro nel file di Excel. Un foglio di lavoro è rappresentato dalla classe Worksheet.

La classe Worksheet fornisce la proprietà PageSetup utilizzata per impostare le opzioni di configurazione della pagina per un foglio di lavoro. L’attributo PageSetup è 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.

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:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a workbook object
Workbook workbook = new Workbook();
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first (default) worksheet
Worksheet worksheet = worksheets[0];
// Get the pagesetup object
PageSetup pageSetup = worksheet.PageSetup;
// Set bottom,left,right and top page margins
pageSetup.BottomMargin = 2;
pageSetup.LeftMargin = 1;
pageSetup.RightMargin = 1;
pageSetup.TopMargin = 3;
// Save the Workbook.
workbook.Save(dataDir + "SetMargins_out.xls");

Centra sulla Pagina

È possibile centrare qualcosa su una pagina orizzontalmente e verticalmente. A tal scopo, ci sono alcuni membri utili della classe PageSetup, CenterHorizontally e CenterVertically.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a workbook object
Workbook workbook = new Workbook();
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first (default) worksheet
Worksheet worksheet = worksheets[0];
// Get the pagesetup object
PageSetup pageSetup = worksheet.PageSetup;
// Specify Center on page Horizontally and Vertically
pageSetup.CenterHorizontally = true;
pageSetup.CenterVertically = true;
// Save the Workbook.
workbook.Save(dataDir + "CenterOnPage_out.xls");

Margini Intestazione e Piè di Pagina

Imposta i margini dell’intestazione e del piè di pagina con i membri della classe PageSetup come HeaderMargin e FooterMargin.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create a workbook object
Workbook workbook = new Workbook();
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.Worksheets;
// Get the first (default) worksheet
Worksheet worksheet = worksheets[0];
// Get the pagesetup object
PageSetup pageSetup = worksheet.PageSetup;
// Specify Header / Footer margins
pageSetup.HeaderMargin = 2;
pageSetup.FooterMargin = 2;
// Save the Workbook.
workbook.Save(dataDir + "CenterOnPage_out.xls");