Use smart marker merge same value argument not works on merged cell

If a multiple column merged cell has setted the smart marker: &=obj.Property(group:merge)
It will works well on different value of each item, but it will throw merge fail exception when process the same value.
Looks it’s still trying to count the merge starting from the first cell of the merged cell instead of checking the cell current merged range.

@Flithor,

Could you please provide us a standalone sample console application (source code without compilation errors), zip the project with resource files (e.g., template Excel file, etc.) and attach here to reproduce the issue. We will check your issue soon.

PS. please use dynamic dataset/datatable or other objects in code while creating the simulation sample project to remove any external dependencies for database/datasource, so we could evaluate/execute your application seamlessly.

class Program
{
    static void Main(string[] args)
    {
        //create template
        var wb = new Workbook();
        var sheet = wb.Worksheets[0];
        //create 2x1 merge cell
        sheet.Cells.CreateRange(0, 0, 1, 2).Merge();
        sheet.Cells[0, 0].Value = "&=obj.Property(group:merge)";
        sheet.Cells[0, 2].Value = "&=obj.AABB";
        //output template file
        const string templateFile = "template.xlsx";
        wb.Save(templateFile);
        Process.Start("cmd", $"/c start {templateFile}");
        var designer = new WorkbookDesigner(wb);
        designer.SetDataSource("obj", new[] { new objClass("Value1", "Value2"), new objClass("Value1", "Value2"), new objClass("Value1", "Value3"), new objClass("Value1", "Value4"), new objClass("Value2", "Value2") });
        designer.Process();

        const string outputFile = "output.xlsx";
        wb.Save(outputFile); //got exception with message:"Cells in range A1:A4 cannot be merged because cells in range A1:B1 have already been merged."
        Process.Start("cmd", $"/c start {outputFile}");
    }
}

internal class objClass
{
    public objClass(string property, string aABB)
    {
        Property = property;
        AABB = aABB;
    }

    public string Property { get; set; }
    public string AABB { get; set; }
}

@Flithor,

I evaluated and tested your code segment a bit. I found you are merging cells (A1:B1) involving group by field. That’s why you are getting this error. When using “group:merge”, Aspose.Cells merges field cells involved. Since you have already merged A1:B1, so you will get the error as it involves existing merged cells. Please remove the line of code:

sheet.Cells.CreateRange(0, 0, 1, 2).Merge();  

and try to use the code segment:
e.g.
Sample code:

class Program
{
    static void Main(string[] args)
    {
        //create template
        var wb = new Workbook();
        var sheet = wb.Worksheets[0];
        sheet.Cells[0, 0].Value = "&=obj.Property(group:merge)";
        sheet.Cells[0, 1].Value = "&=obj.AABB";
        //output template file
        const string templateFile = "template.xlsx";
        wb.Save(templateFile);
        Process.Start("cmd", $"/c start {templateFile}");
        var designer = new WorkbookDesigner(wb);
        designer.SetDataSource("obj", new[] { new objClass("Value1", "Value2"), new objClass("Value1", "Value2"), new objClass("Value1", "Value3"), new objClass("Value1", "Value4"), new objClass("Value2", "Value2") });
        designer.Process();

        const string outputFile = "output.xlsx";
        wb.Save(outputFile); //got exception with message:"Cells in range A1:A4 cannot be merged because cells in range A1:B1 have already been merged."
        Process.Start("cmd", $"/c start {outputFile}");
    }
}

internal class objClass
{
    public objClass(string property, string aABB)
    {
        Property = property;
        AABB = aABB;
    }

    public string Property { get; set; }
    public string AABB { get; set; }
}

Hope, this helps a bit.

Read title of this thread.

I’m reporting a bug that’s (group:merge) not work on the merged cells.
My template file has setted the merge cell format and need to fill data by smart marker.
Merged cell is required template style for me, you should not recommand I remove it!

@Flithor,

Since we already reproduced the issue as you mentioned by using your sample. We found by using (group:merge) smart marker same value argument not working for merged cells. We have logged a ticket with an id “CELLSNET-52236” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@Flithor,

This is to inform you that your issue has been resolved now. The fix will be included in our upcoming release (Aspose.Cells v22.11) which is scheduled in this week. You will also be notified when the next version is released.

The issues you have found earlier (filed as CELLSNET-52236) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi