I've been trying for a while to make the table take up almost the entire width of the Word page, but I haven't been successful. I've used the functions: table_width width fit_to_width without success.
I've been trying for a while to make the table take up almost the entire width of the Word page, but I haven't been successful. I've used the functions: table_width width fit_to_width without success
# Charger la bibliothèque pour manipuler les dataframes
library(officer)
library(flextable)
# Créer les données
colonne1 <- c("Nombre totaux d'arceaux vélo", "Nombre d'arceaux vélos installés")
colonne2 <- c(10, 5)
# Créer le dataframe
df <- data.frame(Colonne1 = colonne1, Colonne2 = colonne2)
#Mise en forme
TABLEAU <- flextable(df) %>%
align(align = "left", part = "all") %>%
bg(bg = "#D3D3D3", part = "header") %>%
bold(part = "header") %>%
align(align = "left", part = "header") %>%
set_caption(paste("BL", commune, "en", annee_prec)) %>%
fit_to_width(max_width = 6.5)%>%
autofit()
TABLEAU
# Créer un nouvel objet Word
doc <- read_docx()
# Ajouter le tableau au document Word
doc <- body_add_flextable(doc, value = TABLEAU)
# Sauvegarder le document Word (you need to change it for you)
print(doc, target = "Desktop/file.docx")