davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
245 stars 44 forks source link

Vertical alignment in FlexTable cells #189

Closed tammoterhark closed 7 years ago

tammoterhark commented 7 years ago

Even though my default settings for tables are vertical alignment = top in my template.docx document when I define a flextable the vertical alignment is always middle/centered.

Did I do something wrong? Is there a command for making vertically aligning table cells? Did I run into a bug?

davidgohel commented 7 years ago

No, use vertical.align = "middle" with function cellProperties. FlexTable has two arguments header.cell.props and body.cell.props that are expecting cellProperties objects.

cellprop <- cellProperties( vertical.align = "bottom" )
MyFTable <- FlexTable( data = iris[46:55, ], 
                       body.cell.props = cellprop, 
                       header.cell.props = cellprop ) 
MyFTable

David

tammoterhark commented 7 years ago

Thanks for the swift answer. But your solution did not have the effect that I hoped for. Perhaps I am overseeing something. The two images show (first picture) what I get and (2) what I hope for.

Using this code:

# Some Flextable settings
cellprop <- cellProperties(vertical.align = "top")
flex_table<-FlexTable(table, header.columns=FALSE, 
                          body.cell.props = cellprop, 
                          header.cell.props = cellprop)
    setFlexTableBorders(flex_table, inner.vertical = borderNone(),
                        inner.horizontal = borderNone(),
                        outer.vertical = borderNone(),
                        outer.horizontal = borderProperties(color = "#006699", style = "solid", width = 2) , 
                        body = TRUE, 
                        header = FALSE,
                        footer = FALSE)

wrong

right

davidgohel commented 7 years ago

Could you provide your sessionInfo() please?

tammoterhark commented 7 years ago
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252    LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C                      
[5] LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggplot2_2.2.1       ReporteRs_0.8.8     ReporteRsjars_0.0.2 stringr_1.2.0       xlsx_0.5.7          xlsxjars_0.6.1      limer_0.1          
 [8] rJava_0.9-8         mailR_0.4.1         lubridate_1.6.0    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9       plyr_1.8.4        R.methodsS3_1.7.1 R.utils_2.5.0     base64enc_0.1-3   tools_3.3.3       digest_0.6.12     jsonlite_1.3     
 [9] tibble_1.2        gtable_0.2.0      png_0.1-7         shiny_1.0.1       DBI_0.6           curl_2.4          officer_0.1.1     httr_1.2.1       
[17] dplyr_0.5.0       xml2_1.1.1        knitr_1.15.1      gdtools_0.1.3     grid_3.3.3        R6_2.2.0          rvg_0.1.3         purrr_0.2.2      
[25] magrittr_1.5      scales_0.4.1      htmltools_0.3.5   assertthat_0.1    mime_0.5          colorspace_1.3-2  xtable_1.8-2      httpuv_1.3.3     
[33] stringi_1.1.2     lazyeval_0.2.0    munsell_0.4.3     R.oo_1.21.0    
davidgohel commented 7 years ago

PowerPoint, Word and HTML outputs are all OK for me... For now, I have no idea why you are in this case. What is the document format you are using?

tammoterhark commented 7 years ago

Sorry, I was not clear about that. Word 365, template attached.

template.docx

davidgohel commented 7 years ago

Your template is ok.

capture d ecran 2017-04-24 a 15 33 39
tammoterhark commented 7 years ago

Thank you for your investigation time. Do you have any idea where I should look for the solution?

tammoterhark commented 7 years ago

Guess ReporteRs itself is not the problem. Maybe it's me...

tammoterhark commented 7 years ago

What code did you use to get this? Maybe I should play around with that..

davidgohel commented 7 years ago

Maybe the viewer, are you using something else then Word usual client (a web viewer for example)?

Below the code:

cellprop <- cellProperties( vertical.align = "top" )
MyFTable <- FlexTable( data = data.frame(text = " ok", text2 = "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "), 
                       body.cell.props = cellprop, 
                       header.cell.props = cellprop ) 

doc = docx(template = "template.docx" )
doc = addFlexTable( doc, flextable = MyFTable )
writeDoc( doc, file = "add_ft_ex.docx" )
tammoterhark commented 7 years ago

Thanks, I play around with that. I'll start with leaving out the border. I'll get back when I either cannot proceed, or when I found a solution.

davidgohel commented 7 years ago

ok, thanks

tammoterhark commented 7 years ago

Problem solved. Beginners fault. Applied properties to other table... :-(

davidgohel commented 7 years ago

:)