Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells provides a class, Workbook, that represents an Excel file. The Workbook class contains the Worksheets collection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class.
The Worksheet class provides the PageSetup property used to set the page setup options for a worksheet. The PageSetup property is an object of the PageSetup class that enables developers to set different page layout options for a printed worksheet. The PageSetup class provides various properties and methods used to set page‑setup options.
Set page margins (left, right, top, bottom) using the PageSetup class members. A few of the methods are listed below which are used to specify page margins:
#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();
}
It is possible to center content on a page horizontally and vertically. For this, there are useful members of the PageSetup class, SetCenterHorizontally() and SetCenterVertically().
#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();
}
Set header and footer margins with the PageSetup class members such as SetHeaderMargin() and SetFooterMargin().
#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"HeaderFooterMargins_out.xls");
std::cout << "Workbook saved successfully with header and footer margins!" << std::endl;
Aspose::Cells::Cleanup();
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.