How can I concatenate several cells with text? [cl

2019-08-31 01:37发布

I use closedXml and I want to concatenate cells which located in one row.

In column E/F/G is what I have. And in column J is that I want to see:

In addition, I want to save bold/italic format

enter image description here

Can anyone help me?

标签: c# closedxml
1条回答
▲ chillily
2楼-- · 2019-08-31 02:17

A little more complicated than I expected it to be but still relative straightforward.
Copy each RichText part from the three source cells to the target cell:

XLWorkbook wb = new XLWorkbook(@"c:\temp.xlsx");
IXLWorksheet worksheet = wb.Worksheet(1);

foreach (IXLRow row in worksheet.RowsUsed())
{
    row.Cell("J").RichText.ClearText();
    foreach (var rt in row.Cell("E").RichText)
    {
        row.Cell("J").RichText.AddText(rt.Text).CopyFont(rt);
    }
    row.Cell("J").RichText.AddText(" ");
    foreach (var rt in row.Cell("F").RichText)
    {
        row.Cell("J").RichText.AddText(rt.Text).CopyFont(rt);
    }
    row.Cell("J").RichText.AddText(" ");
    foreach (var rt in row.Cell("G").RichText)
    {
        row.Cell("J").RichText.AddText(rt.Text).CopyFont(rt);
    }
}

wb.Save();
查看更多
登录 后发表回答