将Word文档复制到文本区域并保留格式

3

我有一些用户需要从Word(或Excel)中复制粘贴内容到文本区域,以便在带有背景的内部网页上显示(因此我不能使用数据图片作为背景,因为它将无法显示)。他们要复制的文本具有颜色和标准字体。

有没有一种简单的方法让用户从Word / Excel中复制到文本区域并保留格式?

以下是他们从Word中复制并微调颜色和间距后使用的文本示例:

<table align="center" border="0">
    <tbody>
        <tr>
            <td>
                <table border="0" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 422pt; border-collapse: collapse; mso-yfti-tbllook: 1184; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" width="563">
                    <tbody>
                        <tr style="height: 33.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
                            <td colspan="2" nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 422pt; height: 33.75pt; background-color: transparent;" width="563">
                                <p align="center" class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Day</font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 1;">
                            <td colspan="2" nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 422pt; height: 33.75pt; background-color: transparent;" width="563">
                                <p align="center" class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Date<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 2;">
                            <td colspan="2" nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 422pt; height: 33.75pt; background-color: transparent;" width="563">
                                <p align="center" class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">OSP #</font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 3;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">TIME1<o:p></o:p></font></span></b></font></p>
                            </td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 1<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>

                        <tr style="height: 33.75pt; mso-yfti-irow: 4;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <font size="160">&nbsp;</font></td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in -10pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 1B<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>

                        <tr style="height: 33.75pt; mso-yfti-irow: 6;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Time2<o:p></o:p></font></span></b></font></p>
                            </td>

                            <td nowrap="nowrap" style="background: rgb(146, 205, 220); border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 7pt;margin-top:7pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Actvity 2<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 6;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <font size="160">&nbsp;</font></td>
                            <td nowrap="nowrap" style="background: rgb(250, 191, 143); border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 2B<o:p></o:p></font></span></b></font></p>
                            </td>   
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 7;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Time3<o:p></o:p></font></span></b></font></p>
                            </td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt; background-color: transparent;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity3<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 8;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <font size="160">&nbsp;</font></td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt; background-color: transparent;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 3B<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 10;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Time4<o:p></o:p></font></span></b></font></p>
                            </td>
                            <td nowrap="nowrap" style="background: rgb(250, 191, 143); border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 7pt;margin-top:7pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 4<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 10;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <font size="160">&nbsp;</font></td>
                            <td nowrap="nowrap" style="background: rgb(146, 205, 220); border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 4B<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 11;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri">Time5<o:p></o:p></font></span></b></font></p>
                            </td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 5<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                        <tr style="height: 33.75pt; mso-yfti-irow: 12; mso-yfti-lastrow: yes;">
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 126.95pt; height: 33.75pt; background-color: transparent;" width="169">
                                <font size="160">&nbsp;</font></td>
                            <td nowrap="nowrap" style="border-color: rgb(240, 240, 240); padding: 0in 5.4pt; width: 295.05pt; height: 33.75pt;" width="393">
                                <p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;">
                                    <font size="160"><b><span new="" style="font-size: 24pt; mso-ascii-font-family: Calibri;" times=""><font face="Calibri"><span style="mso-spacerun: yes;">&nbsp;</span>- Activity 5B<o:p></o:p></font></span></b></font></p>
                            </td>
                        </tr>
                    </tbody>
                </table>

            </td>
        </tr>
    </tbody>
</table>

文本区域没有格式... - Kirk Woll
2个回答

2
这是一个非常复杂的过程,更像是编写应用程序而不是解决简单的复制/粘贴操作。如果您想在浏览器中使用它,还需要涉及JavaScript、插件或Flash。
既然您没有提到重新发明轮子,我认为最好的答案是利用具有“从Word粘贴”支持的富文本编辑器,例如YUI富文本编辑器TinyMCE
这里有一篇关于将Word格式清理干净后粘贴到YUI中的好文章。
希望这能为您提供一个很好的介绍这个非常复杂的主题的入门。

基于这个问题,TinyMCE开发人员决定创建一个完整的插件来粘贴格式化的Word文本。但是不能依赖这些功能,因为Word格式会随着版本的变化而改变。(即使在不同的Word版本中,Word文档也看起来不相等。如果连微软的开发人员都找不到一种可移植的文档格式,那么通过JS模拟导出功能就很困难了。)更不用说OpenOffice或其他办公套件了。 - feeela

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接