Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fontsize() does not modify size of empty cells #153

Open
fabern opened this issue Sep 19, 2019 · 11 comments
Open

fontsize() does not modify size of empty cells #153

fabern opened this issue Sep 19, 2019 · 11 comments
Labels
bug Word related to Word output

Comments

@fabern
Copy link

fabern commented Sep 19, 2019

Hi David,

fontsize() does not modify size of empty cells.
If printed to Word, the corresponding cells have the initial text size.

Best regards,
Fabian

Reproducible example:

dat_frame <- head(iris)

# Make empty cell to show behavior
dat_frame[2,"Species"] <- ""

myft <- flextable::flextable(dat_frame)
myft <- flextable::fontsize(myft, part = "all", size = 4)
myft <- flextable::height_all(myft, height = 0.0001)

print(myft, preview = "docx")

sessionInfo():

R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1          digest_0.6.15       R6_2.2.2            magrittr_1.5        evaluate_0.10.1     zip_2.0.1          
 [7] stringi_1.1.6       rlang_0.3.0.1       gdtools_0.1.7       uuid_0.1-2          data.table_1.10.4-3 xml2_1.2.0         
[13] flextable_0.5.5     rmarkdown_1.11      tools_3.4.3         stringr_1.3.0       officer_0.3.3       yaml_2.2.0         
[19] compiler_3.4.3      base64enc_0.1-3     htmltools_0.3.6     knitr_1.20  
@sbihorel
Copy link

Hi,

It seems that the style of empty cells (NA or "") revert to what the Normal style in the Word template is.
This issue can be quite disruptive since, when one applies a smaller font size compare to the default font size of the Normal style, the height of any row containing empty cells will be different than that of rows that do not contain any empty cells.

Is there a workaround?

@davidgohel
Copy link
Owner

Is there a workaround?

If only about managing NA, you can use:

myft <- set_formatter_type(myft, na_str = " ")

@sbihorel
Copy link

Hi David,

While the workaround you provided works for simple tables, it does not in the complex case I am working on. It is proprietary stuff so I cannot share it and would need to make a vanilla regex that would reproduce the problem.

More generally, I guess one way to solve the problem would be to be able to apply a named Word style on the flextable content (something akin to the style argument of officer::body_add_table for example).

@davidgohel
Copy link
Owner

be able to apply a named Word style on the flextable content

No because this would reduce flextable output to only Word

I'll try to work on that soon

@davidgohel davidgohel added the bug label Jul 15, 2020
@sbihorel
Copy link

Well, the property could be used selectively by body_add_flextable()... Just a thought...

@davidgohel
Copy link
Owner

It's a solution, thanks. but I think it is better to fix it in the xml generation which is text processing only and avoid xml processing that can really slow down the production.

@mattkumar
Copy link

Hi all, just curious to see if this is still a live discussion point. I recently ran up against this myself.

I'm not quite sure how the "set_formatter_type" workaround can be applied - is it possible to elaborate?

Many thanks!

@davidgohel
Copy link
Owner

Yes, it's still open :)

Sorry, I don't have yet a technical solution for this.

For this case, it does not create a "" but a NA as the column is a factor. Then, this workaround can be applied:

library(flextable)
dat_frame <- head(iris)
set_flextable_defaults(na_str = " ")

# Make empty cell to show behavior
dat_frame[2,"Species"] <- ""

myft <- flextable(dat_frame)
myft <- fontsize(myft, part = "all", size = 4)

print(myft, preview = "docx")

@davidgohel
Copy link
Owner

Solution for this issue consists in adding default formatting properties for runs inside paragraphs formatting properties

@abduazizR
Copy link

Hi

I could not understand the solution. Could you please clarify with an example, because I am still facing the same issue

@davidgohel
Copy link
Owner

It's still open :)

Sorry, I don't have yet a technical solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Word related to Word output
Projects
None yet
Development

No branches or pull requests

5 participants