Kenar Boşluklarını C++ ile Ayarlama

Kenar Boşlukları Ayarlama

Aspose.Cells, bir Excel dosyasını temsil eden Workbook adlı bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan Worksheets koleksiyonunu içerir. Bir çalışma sayfası, Worksheet sınıfı ile temsil edilir.

Worksheet sınıfı, bir çalışma sayfası için sayfa düzeni seçeneklerini ayarlamak amacıyla kullanılan PageSetup özelliği sağlar. PageSetup niteliği, geliştiricilerin yazdırılan çalışma sayfası için farklı sayfa düzeni seçenekleri belirlemesine olanak tanıyan PageSetup sınıfının bir nesnesidir. PageSetup sınıfı, sayfa düzeni ayarlarını yapmak için kullanılan çeşitli özellikler ve metodlar sağlar.

Sayfa Kenar Boşlukları

Sayfa kenar boşluklarını (sol, sağ, üst, alt) PageSetup sınıf üyelerini kullanarak belirleyin. İşte sayfa kenar boşluklarını belirtmek için kullanılan birkaç metod:

#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();
}

Sayfa Üzerinde Ortala

Bir şeyi yatay ve dikey olarak sayfada ortalayabilirsiniz. Bunun için PageSetup sınıfının, GetCenterHorizontally() ve GetCenterVertically() üyeleri bazı kullanışlıdır.

#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();
}

Üst Bilgi ve Alt Bilgi Kenar Boşlukları

Başlık ve altbilgi kenar boşluklarını PageSetup sınıf üyeleri olan GetHeaderMargin() ve GetFooterMargin() kullanarak ayarla.

#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();
}