Open fabern opened 5 years ago
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?
Is there a workaround?
If only about managing NA, you can use:
myft <- set_formatter_type(myft, na_str = " ")
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).
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
Well, the property could be used selectively by body_add_flextable()... Just a thought...
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.
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!
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")
Solution for this issue consists in adding default formatting properties for runs inside paragraphs formatting properties
Hi
I could not understand the solution. Could you please clarify with an example, because I am still facing the same issue
It's still open :)
Sorry, I don't have yet a technical solution for this.
It should be fixed in the dev version now
I'm still having some difficulty, If I include the code below in a rmarkdown file and render the report in powerpoint, the "empty" cells have a default font of 13.5 instead of the 7 I specified.
library(dplyr)
library(flextable)
set_flextable_defaults(na_str = " ")
data.frame(Category = c("Ford", "Volkswagen", "Tesla"),
Weight = c(1000, 750, 1200),
Speed = c(60, 45, 70)) %>%
flextable(cwidth = c(2, 1, 1, 2),
col_keys = c("Category", "Weight", "blank", "Speed")) %>%
empty_blanks(width = 0.2,
part = 'all') %>%
fontsize(size = 7,
part = 'all')
Thank you I only looked and fixed word version
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:
sessionInfo():