-
Notifications
You must be signed in to change notification settings - Fork 15
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
Improve wb_set_col_widths(width = "auto")
#1282
Comments
wb_set_col_widths(width = "auto")
Hi @anticmason , indeed Anyhow, maybe we shouldn't strive for perfection and humbly improve the current code. Could you create an example of what specifically you want to see improved? Regarding |
Here comes some codes to accomplish the auto column width by calculate the max width for both title name(field name) and its values and then bind them together to calculate max for all, then use it as a parameter in $set_col_widths(cols=...) from " for circle" 【some functions comes from package:collapse,such as : dapply,fmax,qdf】 summary_list=data.frame(name=c('sheet_name1','sheet_name2,'sheet_name3'),sheet=c('summary_sheet1','summary_sheet2','summary_sheet3')) title1=transpose(qDF(names(get(summary_list$sheet[1])))) title1_width=dapply(title1 %>% mutate(across(seq_len(fncol(title1)),str_width)),max,MARGIN = 2) sheet1_width=dapply(summary_sheet1 %>% mutate(across(seq_len(fncol(summary_sheet1)),str_width)),fmax,MARGIN = 2) sheet1_width = dapply(bind_rows(title1_width,sheet1_width),max,MARGIN = 2) I think set_col_width() should calculate every column(include title name and its values) to decide the correct column width, not just its values....... IF the string width of a column title longer than its values's string width, the column will be indented a lot that the title couldn't be seen normally. In contrast to Excel, when you double click the column width,it will appear to see the title name and its values both。 Looking forward to your reply |
Hi,
When using wb_set_col_widths with width='auto' for auto-fit column width, the result may not be satisfied, as it doesn't take the column name into consideration but only values, I have to write cycles to calculate the max string-width for each columns(column name and values) and then pull them out to xlsx。
Could it be possible to improve this logics by taking the column name and values into consideration together to set col-widths automatically, like autofit method from xlwings package in python? By the way, could it be possible to optimize or create more function refer to xlwings package,since it is really good in excel automation...
Thanks a lot~
looking forward to your reply~
The text was updated successfully, but these errors were encountered: