目前,我有一个excel文档,在多个单元格中具有很多格式(如斜体,粗体和下划线)。我为用户构建了一个Web应用程序,用于将这种样式化的数据复制并粘贴到其中,以便它可以在UI中保持样式化。
我首先想到要使用<textarea/>
元素,但是意识到这不会保留样式。在研究完Google-Fu之后,我遇到了如何添加属性contenteditable
来表示<div>
的问题,然后用户可以使用Command + B来加粗文本等。简单的html标签<b>
或<I>
,可以处理所有出色的事情。它似乎还允许他们从excel复制并粘贴,并且可以保留样式。这个想法是在这里发现的:https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content
不幸的是,在复制和粘贴时,存储的实际字符串包含很多Excel(我认为xhtml)标记...然后将其推送到服务器并会产生很多其他问题/麻烦。 / p>
例如:
This is going to be a big long text Item.
Somethings will be bold.
Other things will be italiciszed.
Lets see if when I copy it into the interface, we actually run into any issues….....
我原本希望是:
This is going to be a big long text Item.
<b>Somethings will be bold.</b>
<I>Other things will be italiciszed.</I>
Lets see if when I copy it into the interface, we actually run into any issues….....
相反,我最终得到了:
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:.75in .7in .75in .7in;
mso-header-margin:.3in;
mso-footer-margin:.3in;}
.font0
{color:black;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
.font5
{color:black;
font-size:12.0pt;
font-weight:700;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
.font6
{color:black;
font-size:12.0pt;
font-weight:400;
font-style:italic;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
td
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:black;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Calibri, sans-serif;
mso-font-charset:0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
-->
</style>
<table border="0" cellpadding="0" cellspacing="0" width="87" style="width: 65pt;">
<colgroup><col width="87" style="width:65pt">
</colgroup><tbody><tr height="21" style="height:16.0pt">
<!--StartFragment-->
<td height="21" width="87" style="height:16.0pt;width:65pt">This is going to be a
big long text Item. <font class="font5">Somethings will be bold.</font><font class="font0"> </font><font class="font6">Other things will be italiciszed.
Lets see if when I copy it into the interface, we actually run into any
issues….....</font></td>
<!--EndFragment-->
</tr>
</tbody></table>
我曾考虑过尝试解析<StartFragment></EndFragment>
之间的句段,然后尝试删除所有“额外”的html标签...但是后来我看到样式注释如何引用顶部的css项目。任何人都有一种优雅的方式来表达我的期望吗?