Çalışma sayfasında Shape Z sırasını değiştirmek ve işlevselliğini öğrenmek için C++ ile Shape Ön veya Arka sıraya gönderin

Olası Kullanım Senaryoları

Aynı konumda birden fazla şekil varsa, görünürlükleri z-sıra konumlarına göre belirlenir. Aspose.Cells, şeklin z-sıra konumunu değiştiren Shape.ToFrontOrBack() yöntemini sağlar. Bir şekli arka plana göndermek istiyorsanız, -1, -2, -3 gibi negatif bir sayı kullanırsınız. Bir şekli en öne almak istiyorsanız, 1, 2, 3 gibi pozitif sayılar kullanırsınız.

Çalışma Sayfası İçinde Şekil Önüne veya Arkasına Gönderme

Aşağıdaki örnek kod, Shape.ToFrontOrBack() yönteminin kullanımını göstermektedir. Lütfen kodda kullanılan örnek Excel dosyasını ve onun tarafından oluşturulan çıkış Excel dosyasını inceleyin. Ekran görüntüsü, kodun çalıştırılmasıyla örnek Excel dosyasındaki etkisini göstermektedir.

todo:image_alt_text

Örnek Kod

#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\\");

    // Load source Excel file
    Workbook wb(srcDir + u"sampleToFrontOrBack.xlsx");

    // Access first worksheet
    Worksheet ws = wb.GetWorksheets().Get(0);

    // Access first and fourth shape
    Shape sh1 = ws.GetShapes().Get(0);
    Shape sh4 = ws.GetShapes().Get(3);

    // Print the Z-Order position of the shape
    std::cout << "Z-Order Shape 1: " << sh1.GetZOrderPosition() << std::endl;

    // Send this shape to front
    sh1.ToFrontOrBack(2);

    // Print the Z-Order position of the shape
    std::cout << "Z-Order Shape 4: " << sh4.GetZOrderPosition() << std::endl;

    // Send this shape to back
    sh4.ToFrontOrBack(-2);

    // Save the output Excel file
    wb.Save(outDir + u"outputToFrontOrBack.xlsx");

    std::cout << "Shapes reordered successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}