开发者

C# export to excel replace <br/> with a line break in a cell

开发者 https://www.devze.com 2023-03-01 13:05 出处:网络
I\'m exporting data to excel. Is it possible to replace <br/> in a string with a line break (alt+enter) so that when exported to excel the string 开发者_高级运维is displayed on separate lines in

I'm exporting data to excel. Is it possible to replace <br/> in a string with a line break (alt+enter) so that when exported to excel the string 开发者_高级运维is displayed on separate lines in the same cell.

For example:

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

Excel:

Number One
Number Two


Only what you need it's add style="mso-data-placement:same-cell;" inside <br /> tag. Data will be displayed on separate lines but in the same cell.

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


string textWithNewLine = text.Replace("<br/>", Environment.NewLine);
0

精彩评论

暂无评论...
验证码 换一张
取 消