I would like to export tables for Excel with formatting from RStudio. Packages as openxlsx work perfect, but I cannot use them in my work situation. It is not possible to install Java or Rtools applications.
The only way to export tables with formatting for Excel seems to copy HTML output (from Markdown), or open the HTML file (from Markdown).
Are there smart starting points that I can use? Examples? CSS examples (for Markdown) that will work for excel?
The only thing that seems to work at the moment is to copy the HTML from the RStudio: Prview HTML. Other ways don't give good results for (my) formatting.
Things I would like to do is header (first row) color and two different colors for all the rest of the rows.
One of the problems is that Excel can only work with one background color.
Update:
So I have to assume that openxlsx will not work for me. The architect.css file from the prettydoc package is showing the same result. See the Markdown code. The output table in the RStudio preview is good. Also in browsers. Copying to Excel is only working from the RStudio preview.
When you open the HTML-file in Excel, Excel is only showing one background color. White in this case.
What I am looking for (I think) is more basic CSS, with a focus on table style. (with two background colors as by :nth-child(n)).
<style>
/*! normalize.css v3.0.2 | MIT License | git.io/normalize */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: local('Open Sans'), local('OpenSans'), url('fonts/open-sans-400.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 700;
src: local('Open Sans Bold'), local('OpenSans-Bold'), url('fonts/open-sans-700.woff') format('woff');
}
html {
font-family: sans-serif; /* 1 */
-webkit-text-size-adjust: 100%; /* 2 */
-ms-text-size-adjust: 100%; /* 2 */
}
/**
* Remove default margin.
*/
body {
margin: 0;
}
/* HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined for any HTML5 element in IE 8/9.
* Correct `block` display not defined for `details` or `summary` in IE 10/11
* and Firefox.
* Correct `block` display not defined for `main` in IE 11.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
menu,
nav,
section,
summary {
display: block;
}
/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/
audio,
canvas,
progress,
video {
display: inline-block; /* 1 */
vertical-align: baseline; /* 2 */
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address `[hidden]` styling not present in IE 8/9/10.
* Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none;
}
/* Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background-color: transparent;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* Text-level semantics
========================================================================== */
/**
* Address styling not present in IE 8/9/10/11, Safari, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/**
* Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/**
* Address styling not present in Safari and Chrome.
*/
dfn {
font-style: italic;
}
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari, and Chrome.
*/
h1 {
margin: 0.67em 0;
font-size: 2em;
}
/**
* Address styling not present in IE 8/9.
*/
mark {
color: #000;
background: #ff0;
}
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
position: relative;
font-size: 75%;
line-height: 0;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9/10.
*/
img {
border: 0;
}
/**
* Correct overflow not hidden in IE 9/10/11.
*/
svg:not(:root) {
overflow: hidden;
}
/* Grouping content
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari.
*/
figure {
margin: 1em 40px;
}
/**
* Address differences between Firefox and other browsers.
*/
hr {
height: 0;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
/**
* Contain overflow in all browsers.
*/
pre {
overflow: auto;
}
/**
* Address odd `em`-unit font size rendering in all browsers.
*/
code,
kbd,
pre,
samp {
font-family: monospace, monospace;
font-size: 1em;
}
/* Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-spacing: 0;
border-collapse: collapse;
width: 50%;
margin: 20px auto;
}
th, td {
border-bottom: 1px solid #bbbbbb;
text-align: left;
padding: 10px;
}
th {
background-color: #63a0e1;
color: white;
}
tr:nth-child(odd) {
background-color: #eeeeee;
}
tr:nth-child(even) {
background-color: #ffffff;
}
/* LAYOUT STYLES */
body {
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.5;
color: #666;
background: #fafafa url(images/body-bg.jpg) 0 0 repeat;
}
p {
margin-top: 0;
}
a {
color: #2879d0;
}
a:hover {
color: #2268b2;
}
header {
padding-top: 40px;
padding-bottom: 20px;
background: #2e7bcf url(images/header-bg.jpg) 0 0 repeat-x;
border-bottom: solid 1px #275da1;
text-align: center;
}
header h1 {
margin-top: 0;
margin-bottom: 0.5em;
font-size: 2em;
font-weight: bold;
line-height: 1;
color: #fff;
letter-spacing: -1px;
}
header h2 {
margin-top: 0;
margin-bottom: 1em;
font-size: 1.5em;
font-weight: normal;
line-height: 1.3;
color: #9ddcff;
letter-spacing: 0;
}
header h3 {
margin-top: 0;
margin-bottom: 1em;
font-size: 1.2em;
font-weight: normal;
line-height: 1.2;
color: #9ddcff;
letter-spacing: 0;
}
.inner, .toc {
position: relative;
width: 840px;
font-size: 1.1em;
margin: 0 auto;
}
.toc {
padding-top: 1em;
padding-bottom: 0;
}
.toc ul {
margin-bottom: 0;
}
#content-wrapper {
padding-top: 30px;
border-top: solid 1px #fff;
}
#main-content img {
max-width: 100%;
}
code {
padding: 0 3px;
background-color: #f2f8fc;
border: solid 1px #dbe7f3;
}
pre {
padding: 20px;
overflow: auto;
text-shadow: none;
background: #fff;
border: solid 1px #f2f2f2;
font-size: 0.9em;
}
pre code {
padding: 0;
color: #2879d0;
background-color: #fff;
border: none;
}
ul, ol, dl {
margin-bottom: 20px;
}
/* COMMON STYLES */
hr {
height: 1px;
margin-top: 1em;
margin-bottom: 1em;
border: 0;
background: #aaa;
background-image: linear-gradient(to right, #eee, #aaa, #eee);
}
form {
padding: 20px;
background: #f2f2f2;
}
/* GENERAL ELEMENT TYPE STYLES */
#main-content h1 {
margin-top: 0;
margin-bottom: 0;
font-size: 2em;
font-weight: bold;
color: #474747;
letter-spacing: -1px;
}
#main-content h1:before {
padding-right: 0.3em;
margin-left: -0.8em;
color: #9ddcff;
content: "/";
}
#main-content h2 {
margin-bottom: 8px;
font-size: 1.5em;
font-weight: bold;
color: #474747;
}
#main-content h2:before {
padding-right: 0.3em;
margin-left: -1.2em;
content: "//";
color: #9ddcff;
}
#main-content h3 {
margin-top: 24px;
margin-bottom: 8px;
font-size: 1.2em;
font-weight: bold;
color: #474747;
}
#main-content h3:before {
padding-right: 0.3em;
margin-left: -1.7em;
content: "///";
color: #9ddcff;
}
#main-content h4 {
margin-bottom: 8px;
font-size: 1.1em;
font-weight: bold;
color: #474747;
}
h4:before {
padding-right: 0.3em;
margin-left: -2em;
content: "////";
color: #9ddcff;
}
#main-content h5 {
margin-bottom: 8px;
font-size: 1em;
color: #474747;
}
h5:before {
padding-right: 0.3em;
margin-left: -2.4em;
content: "/////";
color: #9ddcff;
}
#main-content h6 {
margin-bottom: 8px;
font-size: 0.9em;
color: #474747;
}
h6:before {
padding-right: 0.3em;
margin-left: -3em;
content: "//////";
color: #9ddcff;
}
p {
margin-bottom: 20px;
}
a {
text-decoration: none;
}
p a {
font-weight: 400;
}
blockquote {
padding: 0 0 0 30px;
margin-bottom: 20px;
font-size: 1.1em;
border-left: 10px solid #e9e9e9;
}
ul, ol {
padding-left: 30px;
}
dl dd {
font-style: italic;
font-weight: 100;
}
/* MISC */
.clearfix:after {
display: block;
height: 0;
clear: both;
visibility: hidden;
content: '.';
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* #Media Queries
================================================== */
/* All Mobile Sizes (devices and browser) */
@media only screen and (max-width: 850px) {
.toc, .inner {
width: 93%;
font-size: 1em;
}
header {
padding: 10px 0;
}
header h1, header h2 {
width: 100%;
}
header h1 {
font-size: 1.75em;
}
header h2 {
font-size: 1.2em;
}
header h3 {
font-size: 1em;
}
#main-content h1:before,
#main-content h2:before,
#main-content h3:before,
#main-content h4:before,
#main-content h5:before,
#main-content h6:before {
padding-right: 0;
margin-left: 0;
content: none;
}
}
</style>
```{r, echo=FALSE, results='asis'}
knitr::kable(head(iris, 10), full_width = F)
```