davidgohel / flextable

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

Issue with margins and spacing when cell values are empty characters `""` #661

Closed Melkiades closed 1 month ago

Melkiades commented 2 months ago

The code that follows produces the following video. Notice that I also forced the fonts and font sizes to be correct in another example table, and the margins have the same issue. It is more evident in cases with smaller fonts (9 is our standard). The wrong (larger) margins are only in the cells with no values. Note that also using " " as a workaround does not work for me.

library(flextable)
library(officer)
library(dplyr)

# Creating row names and data for the data frame
rownames <- c("Row1", "Row2", "Row3", "Row4")
col1 <- c("", "", 3, "")
col2 <- c(1, 2, "", 7)
col3 <- c("", "", 11, "")

# Creating the data frame
df <- data.frame(rows = rownames, col1 = col1, col2 = col2, col3 = col3, row.names = rownames)

# Displaying the data frame
print(df)

b <- qflextable(df)
file <- "output.docx"
doc <- officer::read_docx()
doc <- body_add_flextable(doc, b, align = "left")

print(doc, target = file)

2024-09-25_18-08-42

davidgohel commented 2 months ago

It looks like a duplicate of https://github.com/davidgohel/flextable/issues/153, right ?

Melkiades commented 2 months ago

It looks like a duplicate of davidgohel/flextable#153, right ?

Yes it may be! Sorry for that ;) For me the issue is margins because the rest is fixed with this replacement " " -> "", but there margins still do not work correctly. I will follow your workaround and see if it works ^^

davidgohel commented 2 months ago

no pb, this is the oldest issue of flextable.

The issue is identified. It needs new XML attrs that can be used as "default property". I just never took the time to add this as it requires a major update to the code...

davidgohel commented 1 month ago

It should be fixed in the dev version now