bivtbl <- function(n_rijen){
library(gt)
library(readxl) 
library(dplyr, warn.conflicts = FALSE)
excelfile <- "xcl/mijndata.xlsx"
mdat <- read_excel(excelfile, range = cell_cols("A:B"))
x <- mdat |> pull(x)
y <- mdat |> pull(y)
if(!(length(x) == 0 | length(y) == 0  | any(is.na(x)) | any(is.na(y)))) {
   mdat <- read_excel(excelfile, range = cell_cols("C"))
   lbl <- mdat |> pull(lbl)
   if(is.na(lbl[3])) {lbl[3] <- " " }
   if(is.na(lbl[4])) {lbl[4] <- "ID" }
   ID <- paste(lbl[4], as.character(1:length(x)), sep="_")
   df <- head(data.frame(ID, x, y), n_rijen)
   if(!(lbl[1]=="x" | lbl[1]=="y" | is.na(lbl[1]) | lbl[2]=="x" | lbl[2]=="y" | is.na(lbl[2]))) { 
  mtable <- gt(df, rowname_col = "ID") |> 
    tab_stubhead(label = "ID_nr") |> 
    tab_header(title = lbl[3]) |> 
    tab_spanner(
      label = lbl[1],
      columns = x )|> 
    tab_spanner(
      label = lbl[2],
      columns = y )
  mtable
} else {
  mtable <- gt(df, rowname_col = "ID") |> 
    tab_stubhead(label = "ID_nr") |> 
    tab_header(title = lbl[3])
  mtable  
} 
  } else {
      cat("de kolommen met x-data en met y-data \nzijn niet even lang of bevatten lege cellen \npas de gegevens aan in uw Excel bestand: mijndata.xlsx")
    }  
}  