【问题标题】:C# export to excel replace <br/> with a line break in a cellC#导出到excel用单元格中的换行符替换<br/>
【发布时间】:2011-04-28 13:12:37
【问题描述】:

我正在将数据导出到 Excel。是否可以用换行符 (alt+enter) 替换字符串中的&lt;br/&gt;,以便在导出到 excel 时字符串显示在同一行中的不同行上细胞。

例如:

string text = "Number One" + "`<br/>`" + "Number Two"

Excel:

Number One
Number Two

【问题讨论】:

    标签: c# export-to-excel


    【解决方案1】:

    只有你需要它在&lt;br /&gt;标签内添加style="mso-data-placement:same-cell;"。 数据将显示在不同的行但在同一个单元格中。

    <br style="mso-data-placement:same-cell;" />
    

    【讨论】:

      【解决方案2】:
      string textWithNewLine = text.Replace("<br/>", Environment.NewLine);
      

      【讨论】:

      • @Roslyn 确保您的单元格有 Cells[x, y].Style.IsTextWrapped = true;
      • 我正在使用 gridview 导出数据。
      猜你喜欢
      • 1970-01-01
      • 2013-09-10
      • 2011-11-14
      • 1970-01-01
      • 2022-08-07
      • 1970-01-01
      • 2014-06-22
      • 2013-06-19
      • 1970-01-01
      相关资源
      最近更新 更多