How can I concatenate several cells with text? [closed]

邮差的信 提交于 2019-12-13 03:26:41

问题


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

Can anyone help me?


回答1:


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


来源:https://stackoverflow.com/questions/56885548/how-can-i-concatenate-several-cells-with-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!