Skip to content

Encoding issue #103

Description

@marciz

Describe the bug
Encoding issue in sheet names and namedRange

To Reproduce

library(openxlsx)
Sys.setlocale("LC_ALL", "English")
wb <- createWorkbook()
addWorksheet(wb, "Sheet 1")
addWorksheet(wb, "Šhēet 1")
writeData(wb, sheet = "Sheet 1", x = iris, startCol = 1, startRow = 1)
writeData(wb, sheet = "Šhēet 1", x = iris, startCol = 1, startRow = 1)
createNamedRegion(wb = wb, sheet = "Sheet 1", name = "iris", rows = 1:(nrow(iris) + 1), cols = 1:ncol(iris))

# error
createNamedRegion(wb = wb, sheet = 'Šhēet 1', name = "īriš", rows = 1:(nrow(iris) + 1), cols = 1:ncol(iris))

createNamedRegion(wb = wb, sheet = 'Šhēet 1', name = "iris2", rows = 1:(nrow(iris) + 1), cols = 1:ncol(iris))
out_file <- tempfile(fileext = ".xlsx")
saveWorkbook(wb, out_file, overwrite = TRUE)
getNamedRegions(out_file)
head(read.xlsx(xlsxFile = out_file, namedRegion = "iris"))

# error
head(read.xlsx(xlsxFile = out_file, namedRegion = "iris2"))

createNamedRegion(wb = wb, sheet = 'Šhēet 1', name = "īriš", rows = 1:(nrow(iris) + 1), cols = 1:ncol(iris))
Error in createNamedRegion(wb = wb, sheet = "Šheet 1", name = "iriš", :
Invalid characters in name

head(read.xlsx(xlsxFile = out_file, namedRegion = "iris2"))
Error in gsub(sheet, "", region, fixed = TRUE) :
invalid 'pattern' argument

Additional context

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
system code page: 1257

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] openxlsx_4.2.2

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2 Rcpp_1.0.5 stringi_1.5.3 zip_2.1.1

awalker89/openxlsx#433

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions