Impostare margini con C++
Impostazione margini
Aspose.Cells 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 del file Excel. Un foglio di lavoro viene rappresentato dalla classe Worksheet.
La classe Worksheet fornisce la proprietà PageSetup usata per impostare le opzioni di configurazione della pagina per un foglio di lavoro. L’attributo PageSetup è un oggetto della classe PageSetup che permette agli sviluppatori di impostare diverse opzioni di layout di pagina per un foglio di lavoro stampato. La classe PageSetup fornisce varie proprietà e metodi usati per impostare le opzioni di configurazione della pagina.
Margini di Pagina
Imposta margini di pagina (sinistra, destra, superiore, inferiore) utilizzando membri della classe PageSetup. Alcuni dei metodi sono elencati di seguito e vengono usati per specificare i margini di pagina:
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a workbook object
Workbook workbook;
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.GetWorksheets();
// Get the first (default) worksheet
Worksheet worksheet = worksheets.Get(0);
// Get the pagesetup object
PageSetup pageSetup = worksheet.GetPageSetup();
// Set bottom, left, right, and top page margins
pageSetup.SetBottomMargin(2);
pageSetup.SetLeftMargin(1);
pageSetup.SetRightMargin(1);
pageSetup.SetTopMargin(3);
// Save the Workbook
workbook.Save(outDir + u"SetMargins_out.xls");
std::cout << "Margins set successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Centra sulla Pagina
È possibile centrare qualcosa su una pagina orizzontalmente e verticalmente. Per questo, ci sono alcuni membri utili della classe PageSetup, GetCenterHorizontally() e GetCenterVertically().
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a workbook object
Workbook workbook;
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.GetWorksheets();
// Get the first (default) worksheet
Worksheet worksheet = worksheets.Get(0);
// Get the pagesetup object
PageSetup pageSetup = worksheet.GetPageSetup();
// Specify Center on page Horizontally and Vertically
pageSetup.SetCenterHorizontally(true);
pageSetup.SetCenterVertically(true);
// Save the Workbook
workbook.Save(outDir + u"CenterOnPage_out.xls");
std::cout << "Workbook saved successfully with centered page setup!" << std::endl;
Aspose::Cells::Cleanup();
}
Margini Intestazione e Piè di Pagina
Imposta i margini di intestazione e piè di pagina con membri della classe PageSetup come GetHeaderMargin() e GetFooterMargin().
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a workbook object
Workbook workbook;
// Get the worksheets in the workbook
WorksheetCollection worksheets = workbook.GetWorksheets();
// Get the first (default) worksheet
Worksheet worksheet = worksheets.Get(0);
// Get the pagesetup object
PageSetup pageSetup = worksheet.GetPageSetup();
// Specify Header / Footer margins
pageSetup.SetHeaderMargin(2);
pageSetup.SetFooterMargin(2);
// Save the Workbook
workbook.Save(outDir + u"CenterOnPage_out.xls");
std::cout << "Workbook saved successfully with centered header and footer margins!" << std::endl;
Aspose::Cells::Cleanup();
}