Impostazione dei margini

Impostazione dei margini

Aspose.Cells offre un corso,Cartella di lavoro , che rappresenta un file Excel. IlCartella di lavoro classe contiene ilFogli di lavoro raccolta che consente l’accesso a ciascun foglio di lavoro nel file Excel. Un foglio di lavoro è rappresentato daFoglio di lavoroclasse.

IlFoglio di lavoro la classe fornisce ilImpostazione della pagina proprietà utilizzata per impostare le opzioni di impostazione della pagina per un foglio di lavoro. IlImpostazione della pagina l’attributo è un oggetto delImpostazione della pagina classe che consente agli sviluppatori di impostare diverse opzioni di layout di pagina per un foglio di lavoro stampato. IlImpostazione della paginaclass fornisce varie proprietà e metodi utilizzati per impostare le opzioni di impostazione della pagina.

Margini della pagina

Impostare i margini della pagina (sinistra, destra, superiore, inferiore) utilizzandoImpostazione della paginamembri della classe. 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. Per questo, ci sono alcuni utili membri delImpostazione della pagina classe,CentroOrizzontalmente eCentroVerticale.

// 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 di intestazione e piè di pagina

Imposta i margini di intestazione e piè di pagina con il fileImpostazione della pagina membri della classe comeIntestazioneMargine ePiè di paginaMargin.

// 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");