简体   繁体   中英

How i can merge Microsoft Word table cells horizontally using OpenXML C#

I have a table in Microsoft Word. I need to merge two cells in a row of a table. I get the cells I need:

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);

How I can merge these cells horizontally?

You need to append a HorizontalMerge object to the cell's 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM