简体   繁体   English

使用特定的 CSS (clipboard.js) 将表格复制并粘贴到 MS Word

[英]Copy & Paste Table to MS Word using specific CSS (clipboard.js)

I am struggling with the following: I am trying to copy a simple HTML table to MS Word (A4 page size) by using clipboard.js.我正在努力解决以下问题:我正在尝试使用 clipboard.js 将一个简单的 HTML 表格复制到 MS Word(A4 页面大小)。 This works generally fine.这通常工作正常。

The table width ist set to 100% in CSS, but in MS Word it extends outside the page.表格宽度在 CSS 中设置为 100%,但在 MS Word 中它扩展到页面之外。 Is there any way to define a CSS rule that applies 100% width in the browser and fits in Word (15,99 cm)?有什么方法可以定义在浏览器中应用 100% 宽度并适合 Word (15,99 cm) 的 CSS 规则?

So what I would like to achieve:所以我想达到的目标:
CSS in Browser: width: 100%;浏览器中的 CSS:宽度:100%;
CSS for copying to WORD: width: 15,99cm;复制到 WORD 的 CSS:宽度:15,99cm;

I tried using @media queries (to apply the CSS only in the browser), but had no luck.我尝试使用 @media 查询(仅在浏览器中应用 CSS),但没有运气。 Any other ideas?还有其他想法吗? Preferably in pure CSS.最好是纯 CSS。

Thanks :-)谢谢 :-)

 new ClipboardJS('.btn');
 .resultsTable { width: 100%; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"></script> <!-- Target --> <table id="foo" class="resultsTable"> <tbody> <tr> <td style="background-color: #eeeeee; font-weight: bold; width: 100%;" colspan="4"> <p><span style="font-size: 18px; font-weight: bold;">"Unentschieden&rdquo;-Antworten</span></p> </td> </tr> <tr> <td style="font-weight: bold; width: 50%;" width="50%"> <p><strong>Skala</strong></p> </td> <td style="font-weight: bold; width: 10%;" width="10%"> <p><strong>RW</strong></p> </td> <td style="font-weight: bold; width: 10%;" width="10%"> <p><strong>PR</strong></p> </td> <td style="font-weight: bold; width: 30%;" width="30%"> <p><strong>Text</strong></p> </td> </tr> <tr> <td width="50%"> <p>Schule</p> </td> <td width="10%"> <p>18</p> </td> <td width="10%"> <p>90-100</p> </td> <td width="30%"> <p>extrem &uuml;ber &Oslash;</p> </td> </tr> <tr> <td width="50%"> <p>Freizeit</p> </td> <td width="10%"> <p>18&nbsp;</p> </td> <td width="10%">90-100</td> <td width="30%"> <p>extrem &uuml;ber &Oslash;</p> </td> </tr> <tr> <td width="50%"> <p>Familie</p> </td> <td width="10%"> <p>18</p> </td> <td width="10%"> <p>90-100</p> </td> <td width="30%"> <p>extrem &uuml;ber &Oslash;</p> </td> </tr> <tr> <td width="50%"> <p>Gesamt</p> </td> <td width="10%"> <p>54</p> </td> <td width="10%"> <p>90-100</p> </td> <td width="30%"> <p>extrem &uuml;ber &Oslash;</p> </td> </tr> </tbody> </table> <!-- Trigger --> <button class="btn" data-clipboard-target="#foo"> COPY </button>

I was able to solve the issue by simply defining width as an html attribute for the table and not as a css style:我能够通过简单地将宽度定义为表格的 html 属性而不是 css 样式来解决这个问题:

<table width="100%">

See https://jsfiddle.net/8za2sv6r/https://jsfiddle.net/8za2sv6r/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM