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

treat namedRegion as dims #37

Open
JanMarvin opened this issue Jan 17, 2022 · 6 comments
Open

treat namedRegion as dims #37

JanMarvin opened this issue Jan 17, 2022 · 6 comments
Assignees
Labels
enhancement 😀 New feature or request

Comments

@JanMarvin
Copy link
Owner

when calling writeData() it should be possible to easily write into a named region instead of just dims

@JanMarvin
Copy link
Owner Author

well, at least for now it's possible to write a named redgion. one step at a time

@JanMarvin JanMarvin added this to the rc2 milestone Mar 8, 2022
@JanMarvin JanMarvin added the enhancement 😀 New feature or request label Mar 8, 2022
@JanMarvin
Copy link
Owner Author

Maybe a named region can be used with empty dims and namedRegion2dims(). Will think about it a bit more.

@JanMarvin
Copy link
Owner Author

getNamedRegions() already provides all we need. We even split sheet name and dims. Not sure why we never picked it up. We can use the top left corner as a starting point and rewrite the named region for the size we are writing.

@JanMarvin JanMarvin modified the milestones: v0.3.0 rc2, v0.5 Dec 6, 2022
@JanMarvin JanMarvin self-assigned this Dec 29, 2022
@JanMarvin JanMarvin modified the milestones: v0.5, v0.6 Jan 29, 2023
@JanMarvin
Copy link
Owner Author

JanMarvin commented Feb 25, 2023

I started work on #548 I wanted to improve the ability sketched below

library(openxlsx2)

# create a workbook with a named region
wb <- wb_workbook() |>
  wb_add_worksheet() |>
  wb_add_named_region(
    name = "named_region",
    dims = wb_dims(
      rows = 5:7,
      cols = 6:8
    )
  )

# get the named region
nr <- wb$get_named_regions()
nr
#>           name               value  sheets coords id local sheet
#> 1 named_region 'Sheet 1'!$F$5:$H$7 Sheet 1  F5:H7  1     0     1

# create a matrix of 1
mat <- dims_to_dataframe(nr$coords)
mat[is.na(mat)] <- 1

# write the data on the sheet
wb$add_data(sheet = nr$sheets, dims = nr$coords, x = mat, colNames = FALSE)

# read the data from the sheet
wb_to_df(wb, sheet = nr$sheets, dims = nr$coords, colNames = FALSE)
#>   F G H
#> 5 1 1 1
#> 6 1 1 1
#> 7 1 1 1

@JanMarvin
Copy link
Owner Author

Should add some update named region function by name and sheet

@olivroy olivroy removed this from the v0.7 milestone Nov 17, 2023
@JanMarvin
Copy link
Owner Author

Maybe we can integrate this into an assert_dims() function. Updated code snippet above, still this is something that I really really like to see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 😀 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants