0

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.

Madaga
  • 1
  • Have you tried these approaches: https://stackoverflow.com/questions/69400178/how-to-save-a-gt-table-to-either-an-excel-or-word-file. I believe `writeData` has it's own style arguments, so it's likely that this is overwriting any styles implemented before you pass it to `writeData`. – nrennie Jun 07 '23 at 11:47

0 Answers0