Create Union Range with C++

Create Union Range

Aspose.Cells provides the ability to create Union Range by using the CreateUnionRange method. The CreateUnionRange method accepts two parameters, the address to create the union range and the index of the worksheet. The CreateUnionRange method returns a UnionRange object.

The following code snippet demonstrates creating a Union Range by using the CreateUnionRange method. The output file generated by the code is attached for reference.

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // Create a Workbook object
    Workbook workbook;

    // Create union range
    UnionRange unionRange = workbook.GetWorksheets().CreateUnionRange(u"sheet1!A1:A10,sheet1!C1:C10", 0);

    // Put value "ABCD" in the range
    unionRange.SetValue(u"ABCD");

    // Save the output workbook
    workbook.Save(u"CreateUnionRange_out.xlsx");

    std::cout << "Union range created and workbook saved successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}