Invia forma in primo o in secondo piano all’interno del foglio di lavoro con C++
Contents
[
Hide
]
Possibili Scenari di Utilizzo
Quando ci sono più forme presenti nello stesso luogo, la loro visibilità è determinata dalle loro posizioni di z-ordine. Aspose.Cells offre il metodo Shape.ToFrontOrBack(), che cambia la posizione di z-ordine della forma. Se si desidera inviare una forma in background, si utilizza un numero negativo come -1, -2, -3, ecc. Se si desidera portare una forma in primo piano, si utilizza un numero positivo come 1, 2, 3, ecc.
Invia la forma avanti o indietro all’interno del foglio di lavoro
Il seguente esempio di codice dimostra l’uso del metodo Shape.ToFrontOrBack(). Si prega di consultare il file Excel di esempio utilizzato nel codice e il file Excel di output generato da esso. Lo screenshot mostra l’effetto del codice sul file Excel di esempio all’esecuzione.
Codice di Esempio
#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();
}