代码之家  ›  专栏  ›  技术社区  ›  bvl

如何使用OpenXML C水平合并Microsoft Word表格单元格#

  •  5
  • bvl  · 技术社区  · 7 年前

    我有一张Microsoft Word表格。 我需要合并表中一行的两个单元格。 我得到了我需要的细胞:

    Wordprocessing.TableRow row = table.Elements<Wordprocessing.TableRow>().ElementAt(i);
    
     Wordprocessing.TableCell cell1 = row.Elements<Wordprocessing.TableCell>().ElementAt(j);
    
     Wordprocessing.TableCell cell2 = row.Elements<Wordprocessing.TableCell>().ElementAt(j+1);
    

    如何水平合并这些单元格?

    1 回复  |  直到 7 年前
        1
  •  12
  •   pushasha    7 年前

    您需要附加 HorizontalMerge 对象到单元格的 TableProperties

    TableCellProperties cellOneProperties = new TableCellProperties();
    cellOneProperties.Append(new HorizontalMerge()
    {
        Val = MergedCellValues.Restart
    });
    
    TableCellProperties cellTwoProperties = new TableCellProperties();
    cellTwoProperties.Append(new HorizontalMerge()
    {
        Val = MergedCellValues.Continue
    });
    
    cell1.Append(cellOneProperties);
    cell2.Append(cellTwoProperties);