I want to export a tbale generated using gt() into excel using write.Data()
gt() allows me to add column labels with common tabs.
wt1 <-gt(data=wt1)
wt1 <- wt1 %>%
cols_label(starts_with("Freq") ~ "Freq",
starts_with("%") ~ "%")%>%
tab_spanner(label = "Group 1", columns = c(2,3)) %>%
tab_spanner(label = "Group 2", columns = c(4,5)) %>%
tab_spanner(label = "Total" , columns = c(6,7)) %>%
cols_align(
align = "left",
columns = var)
I got a well-formatted table.
But when I tried to export this to excel. All the formating was gone. There were no column labels.
writeData(wb,"sheet",(wt1), startCol = 1, startRow = 1,
rowNames = F, colNames = T )
How do I export the gt() table to Excel keeping the formatting intact? I like using writ.Data() as I provide a lot of flexibility in terms of adding headers, and footers or specifying the sheet where data needs to be pasted.