Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing some formatting options... #4

Open
adamdsmith opened this issue Sep 7, 2017 · 13 comments
Open

Exposing some formatting options... #4

adamdsmith opened this issue Sep 7, 2017 · 13 comments

Comments

@adamdsmith
Copy link

adamdsmith commented Sep 7, 2017

I regularly use openxlsx to generate spreadsheets for colleagues. These spreadsheets make use of such formatting options as: freeze panes, autofiltering, auto or manual column widths, and formatted dates and hyperlinks.

Would love to see these options in writexl.

For example...

library(openxlsx)
options("openxlsx.dateFormat" = "yyyy-mm-dd")

df <- data.frame(url = rep("https://ropensci.org/blog/technotes/2017/09/08/writexl-release", 5),
                 date = seq.Date(from = as.Date("2017-09-08"), by = 1, length.out = 5),
                 topic = paste("writexl package announced", 0:4, "days ago!"),
                 stringsAsFactors = FALSE)

class(df$url) <- "hyperlink"
wb <- createWorkbook()
urls <- which(names(df) == "url")
addWorksheet(wb, "test worksheet")

# Manual column widths
col_widths <- c(11, 10, 36)
setColWidths(wb, 1, cols = seq_along(df), widths = col_widths)

# Freeze panes
freezePane(wb, 1, firstRow = TRUE)

# Write and add autofilter
writeData(wb, 1, df, withFilter = TRUE)

# Change hyperlink display text
writeData(wb, sheet = 1, x = rep("this is a link", nrow(df)),
          startRow = 2, startCol = urls)

# Save output
saveWorkbook(wb, "C:/temp/test.xlsx")
@stephLH
Copy link

stephLH commented Sep 11, 2017

+1 !
I especially use the setColWidths function in openxlsx to auto-adjust colum width.

@ThoDuyNguyen
Copy link

some basic formatting for table header would be nice, just like as params asTable of openxlsx.write.xlsx

@rdatasculptor
Copy link

@jeroen, any plans in adding some formatting options? I agree with @stephLH on his remark about setColWidths function that auto-adjusts column width. Writexl really is a great package that does it's job very easily. My colleagues like it when I use it to make data available in excel. However, their first impression would be much more positive if the column width would be automatically set right. The adjustment of the column width is the first thing really every user, including myself, does manually after opening the generated Excel file. Always. It's the first thing that is needed for eveyone to make the data readable. So I was just wondering :-)

@superkeyor
Copy link

Personally, I would like to have autofilter options added 👍 :)

@StephieLaPugh
Copy link

Agree with all of the above! Great package so far; these things would make it even better.

P.S. Death to clippy.

@katrinleinweber
Copy link

+1 for freezePane :-)

@nr0cinu
Copy link

nr0cinu commented Jan 8, 2020

+1 for freeze panes too! Would also be nice to format the columns differently :)

@jcbannon
Copy link

Love the package, but auto column widths would be great.

@gitnirajky
Copy link

Currently Format header format_headers = TRUE allows to have col_names in the xlsx centered and bold. Can we have option to keep them aligned on left but bold or as needed. It does not make sense for to rows align to left but header to center, what we still want to keep is bold headers. Some users complains because center aligned headers are not properly readable without adjusting width. Hope this make sense.

@jmcnamara
Copy link
Contributor

jmcnamara commented Jun 8, 2021

From a libxlsxwriter point of view the feasibility/difficulty of the formatting features requested above is:

  1. openxlsx.dateFormat. Relatively easy. This can be done with the existing writexl code.
  2. Manual column widths col_widths <- c(11, 10, 36): Relatively easy in libxlsxwriter. However, autofit columns aren't currently supported since it isn't part of the file format and would have to be simulated.
  3. Freeze panes freezePane(wb, 1, firstRow = TRUE): This is pretty straightforward in libxlsxwriter.
  4. Write and add autofilter writeData(wb, 1, df, withFilter = TRUE). This is also relatively straightforward.
  5. asTable: Tables aren't supported in libxlsxwriter yet (but are supported in xlsxwriter like this Pandas example ). It should be available in the next few months. Update: it is available now.
  6. Header formatting. Relatively easy. This can be done mainly with the existing writexl code.

If there is interest I could try implement examples of most of these, apart from number 5 (for now).

@jeroen
Copy link
Member

jeroen commented Jun 8, 2021

I'm worried that formatting is a rabbit hole that will introduce a lot of complexity that I don't have time to review or maintain. The primary goal of writexl is to be simple, fast and reliable to make R data accessible to excel users. Formatting is beyond the scope of what I had in mind.

If there is some low hanging fruit that is trivial to implement, and widely useful, we could add it, but I am very worried of feature creep when we start adding all the one-off formatting feature requests.

@samkulu
Copy link

samkulu commented Jun 1, 2022

Could a pre-formatted template be the solution? Unfortunately, I don't know how intertwined the formatting is with the data in the zip file. But maybe there is somehow a possibility to use the XML Source or maybe an option with SourceData. See
Overview of XML in Excel

@rix133
Copy link

rix133 commented Mar 29, 2023

I understand that introducing this complexity might be something the maintainer does not want to incorporate. So anybody really needing this can use my fork to introduce some of this behavior:

if (!require(devtools)) {
  install.packages("devtools")
}

# Install the writexl package from the forked GitHub repository
devtools::install_github("rix133/writexl")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests