ycphs / openxlsx

openxlsx - a fast way to read and write complex xslx files
https://ycphs.github.io/openxlsx/
Other
220 stars 74 forks source link

type "topN" and "bottomN" not working as expected in openxlsx::conditionalFormatting #401

Closed jw388743 closed 7 months ago

jw388743 commented 1 year ago

Describe the bug See title

To Reproduce

R version 4.2.1

openxlsx version: 4.2.5

wb <- openxlsx::createWorkbook()

sheetNms <- c(
  "topN",
  "bottomN",
  "topPercent",
  "bottomPercent"
)

## Add Sheets
purrr::walk(sheetNms, ~ openxlsx::addWorksheet(wb, .x))

## Write Data 
purrr::walk(sheetNms, ~ openxlsx::writeData(wb, .x, mtcars))

## Add styles 
purrr::pwalk(
  list(
    sheetNms,
    1:4,
    c("topN", "bottomN", "topN", "bottomN"),
    c(FALSE, FALSE, TRUE, TRUE),
    c(5, 10, 15, 20)
  ),
  function(sheetNm, .col, fmtType, pct, rnk) {
    openxlsx::conditionalFormatting(
      wb,
      ## sheet nms same as fmtType
      sheetNm,
      cols = .col,
      ## all rows but colnames 
      rows = 2:(nrow(mtcars) + 1),
      type = fmtType,
      percent = pct,
      rank = rnk,
      style = openxlsx::createStyle(fontColour = "black",
                                    bgFill = "yellow")
      )
  }
)

openxlsx::saveWorkbook(wb, "openxlsx cntlFmormat Bug.xlsx")

Expected behavior

Screenshots

image

image

image

image

github-actions[bot] commented 7 months ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 7 months ago

This issue was closed because it has been stalled for 7 days with no activity.