js导出excel单元格内换行符代码,将带有换行符的HTML字符串粘贴到单个Excel单元格中...

该博客探讨了如何在Excel单元格中插入包含HTML格式(颜色、粗体、斜体等)且保留换行符的文本。作者遇到的问题是,当文本包含换行符时,Excel会将它们分开成不同的单元格。通过使用mso-data-placement:same-cell样式并未得到预期效果。解决方案是利用System.Text.StringBuilder对象构建字符串,并在VBA代码中使用Paste方法,成功实现了在单个单元格内保持格式和换行。
摘要由CSDN通过智能技术生成

I'm trying to insert HTML/RTF formatted text into a single Excel cell, preserving text formatting (colour, bold, italic etc.).

The problem is that if the text contains line breaks (
), parts of the text between the breaks is inserted into separate cells.

d4c259939fcec917e31d7dea1bc1c566.png

I tried , but it seems to be ignored by Excel's parser and treated like a normal
.

A lot of topics on forums say that mso-data-placement:same-cell lets you have new line breaks inside a cell, but in my case this style is ignored.

How do I achieve text formatting and line breaks when pasting text into a single cell?

My code (simplified a bit):

Private Sub Worksheet_Change2(ByVal Target As Range, ByVal sht As Worksheet)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值