您好,我的需求表格如Template1所示,因为要动态添加列,所以用了SpilitCell,最后想合并第一行内容相同的列,出现了Template3这样的情况。用ApplyHorizontalMerge合并也是这样。我很确定是SplitCell的问题,因为正常Merge是可行的。请问有什么解决方法或别的动态添加列的思路吗?
- Code: Select all
class Template
{
public string Group { get; set; }
public string Name { get; set; }
}
List<Template> list = new List<Template>
{
new Template { Group = "基础类型", Name = "基础A" },
new Template { Group = "基础类型", Name = "基础B" },
new Template { Group = "特殊类型", Name = "特殊A" },
new Template { Group = "特殊类型", Name = "特殊B" },
new Template { Group = "特殊类型", Name = "特殊C" }
};
for (row = 0; row < 5; row++)
{
col = row < 2 ? 1 : 2;
table[row, col].SplitCell(list.Count, 1);
if (row < 2)
{
list.ForEach((item, i) =>
{
table[row, 1 + i].FirstParagraph.Text = row == 0 ? item.Group : item.Name;
if(row == 0)
{
table[row, 1 + i].CellFormat.HorizontalMerge = table[row, 1 + i].FirstParagraph.Text == table[row, i].FirstParagraph.Text ? CellMerge.Continue : CellMerge.Start;
}
});
}
}