Create Union Range

Create Union Range

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

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Working directories
string SourceDir = RunExamples.Get_SourceDirectory();
string outputDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(SourceDir + "SamplePowerQueryFormula.xlsx");
DataMashup mashupData = workbook.DataMashup;
foreach (PowerQueryFormula formula in mashupData.PowerQueryFormulas)
{
foreach (PowerQueryFormulaItem item in formula.PowerQueryFormulaItems)
{
if (item.Name == "Source")
{
item.Value = "Excel.Workbook(File.Contents(\"" + SourceDir + "SamplePowerQueryFormulaSource.xlsx" + "\"), null, true)";
}
}
}
// Save the output workbook.
workbook.Save(outputDir + "SamplePowerQueryFormula_out.xlsx");