Import HTML table with CSS to MS Word

7

I have created a table below using R with HTML code attached at the end of the question.

enter image description here

The default output from R fits perfectly my need, but I need table to be shown and editable in MS Word. I tried: i) copy-and-paste the table from firefox to MS Word; and ii) open the html file using MS Word. Both give me table with distorted style.

Is there anyway to copy the table as it is seen below from HTML to word?

<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
 <style>table { border-collapse:collapse; border:none; }
th { border-bottom: 1px solid; }
table td { padding:0.2cm; }
.summary td { padding-top:0.1cm; padding-bottom:0.1cm }
.colnames td { font-style:italic }
.firstsumrow { border-top:1px solid }
.lasttablerow { border-bottom: double; }
.topborder { border-top:2px solid }
.depvarhead { text-align:center; border-bottom:1px solid; border-top:1px solid }
.topcontentborder { border-top:double }
.annorow { border-top:2px solid }
.annostyle { text-align:right }
</style> 
</head>
<body> 
 <table>
   <tr class="topborder">
    <td rowspan="2"><em>Predictors</em></td> 
     <td colspan="3" class="depvarhead"><em>Dependent Variables</em></td> 
   </tr>
  <tr> 
     <td colspan="3">Barthel-Index</td> 
   </tr> 
   <tr class="colnames">
    <td>&nbsp;</td>
     <td>B (CI)</td><td>std. Beta</td><td>p</td>
   </tr>
   <tr class="topcontentborder"> 
     <td>(Intercept)</td> 
     <td>93.76 (85.95-101.57)</td> <td></td><td><b>0.000</b></td> 
   </tr> 
   <tr>
     <td>Carer's Age</td> 
     <td>-0.55 (-0.69--0.41)</td> <td>-0.25</td><td><b>0.000</b></td> 
   </tr> 
   <tr class="summary firstsumrow">
    <td>Observations</td>
     <td colspan="3">880</td>
   </tr>
   <tr class="summary">
     <td>R<sup>2</sup> / adj. R<sup>2</sup></td>
     <td colspan="3">0.061 / 0.060</td>
   </tr>
   <tr class="summary">
     <td>AIC</td>
     <td colspan="3">8424.34</td>
   </tr>
   <tr class="annorow">
    <td>Notes</td><td class="annostyle" colspan="3"><em>* p&lt;0.005&nbsp;&nbsp;&nbsp;** p&lt;0.01&nbsp;&nbsp;&nbsp;*** p&lt;0.001</em></td>
  </tr>
</table> 
 </body></html> 

lokheart

Posted 2014-02-26T15:17:19.667

Reputation: 473

Answers

1

Import to libreoffice, save as .doc and open in Word. Libreoffice does a better job of importing html tables.

Misha

Posted 2014-02-26T15:17:19.667

Reputation: 195

0

I believe you can open HTML files as HTML files in word. So save the file to a location and then open it with word.

codehitman

Posted 2014-02-26T15:17:19.667

Reputation: 171

nope, i tried but the format still gets distorted, actually i tried that before the question is asked – lokheart – 2014-02-26T15:25:33.143

0

You can do this with insert object. In the Insert ribbon, under the Text tab, go to Object - Text from file.

You may have to alter it afterwards, such as formatting etc as there some subtle differences but it isn't bad!

enter image description here

Dave

Posted 2014-02-26T15:17:19.667

Reputation: 24 199

1sorry for being picky, but I need to repeat the formatting work for several dozens of tables, it would be good if formatting can also be inherited to MS Word. – lokheart – 2014-02-26T15:41:41.700

2I can't see where your state that in your original question. – Dave – 2014-02-26T17:07:45.573