davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
554 stars 79 forks source link

Border is not displayed correctly in docx output? #577

Closed hughjonesd closed 11 months ago

hughjonesd commented 11 months ago

Here's a minimal example. In the Rstudio internal HTML viewer, I see a border above the final row, first column. When I save as html (or other formats), I see that. But if I save as docx, the border doesn't appear.

library(flextable)
ft <- flextable(mtcars[1:3, 1:3])
# ft <- merge_at(ft, i = 1:2, j = 1) # I thought this mattered but it seems not to.
ft <- border(ft, i = 3, j = 1,
  border.top = officer::fp_border(width = 1)
)
ft
save_as_html(ft, path = "tmp.html")
save_as_docx(ft, path = "tmp.docx")

This is with flextable 0.9.3 and R 4.3.0, on a Mac. (More info below.)

I thought this relates to huxtable issue: hughjonesd/huxtable#246. Now I'm not so sure because I get the same bug even when the merge_at line is commented out.

Apologies if I'm misunderstanding something.

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 14.0

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/London
tzcode source: internal

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

other attached packages:
[1] knitr_1.43      flextable_0.9.3 dplyr_1.1.2     huxtable_5.5.2 

loaded via a namespace (and not attached):
 [1] sass_0.4.6              utf8_1.2.3              generics_0.1.3         
 [4] fontLiberation_0.1.0    xml2_1.3.4              stringi_1.7.12         
 [7] httpcode_0.3.0          digest_0.6.31           magrittr_2.0.3         
[10] evaluate_0.21           grid_4.3.0              fastmap_1.1.1          
[13] jsonlite_1.8.5          zip_2.3.0               crul_1.4.0             
[16] promises_1.2.0.1        fansi_1.0.4             fontBitstreamVera_0.1.1
[19] jquerylib_0.1.4         textshaping_0.3.6       cli_3.6.1              
[22] shiny_1.7.4             rlang_1.1.1             fontquiver_0.2.1       
[25] crayon_1.5.2            ellipsis_0.3.2          cachem_1.0.8           
[28] yaml_2.3.7              withr_2.5.0             gfonts_0.2.0           
[31] gdtools_0.3.3           tools_4.3.0             officer_0.6.2          
[34] uuid_1.1-0              httpuv_1.6.11           curl_5.0.1             
[37] assertthat_0.2.1        vctrs_0.6.2             R6_2.5.1               
[40] mime_0.12               lifecycle_1.0.3         stringr_1.5.0          
[43] ragg_1.2.5              pkgconfig_2.0.3         bslib_0.5.0            
[46] pillar_1.9.0            later_1.3.1             data.table_1.14.8      
[49] glue_1.6.2              Rcpp_1.0.10             systemfonts_1.0.4      
[52] xfun_0.39               tibble_3.2.1            tidyselect_1.2.0       
[55] rstudioapi_0.14         xtable_1.8-4            htmltools_0.5.5        
[58] rmarkdown_2.22          compiler_4.3.0          askpass_1.1            
[61] openssl_2.0.6     
davidgohel commented 11 months ago

Hello David

This is about border(), I strongly advise to not use it but to use other functions dedicated for border management. See the manual for advised functions, here hline() is totally fine.

https://davidgohel.github.io/flextable/reference/border.html

library(flextable)
ft <- flextable(mtcars[1:3, 1:3])
ft <- hline(ft, i = 2, j = 1, border = officer::fp_border(width = 1))
ft
save_as_html(ft, path = "tmp.html")
save_as_docx(ft, path = "tmp.docx")

KR, David

github-actions[bot] commented 5 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.