Giter Site home page Giter Site logo

Encoding issue about tidyxl HOT 6 CLOSED

nacnudus avatar nacnudus commented on August 16, 2024
Encoding issue

from tidyxl.

Comments (6)

nacnudus avatar nacnudus commented on August 16, 2024

Thanks. I will look at this soon.

Note to self: readxl uses SET_STRING_ELT(cols[7], c, Rf_mkCharCE("text", CE_UTF8)); but when I tried this before, Encoding() still returned "unknown". I want to avoid Encoding() <- "UTF-8" because it copies potentially huge vectors/dataframes.

from tidyxl.

nacnudus avatar nacnudus commented on August 16, 2024

@stla If you have "Stéphane" in a cell, does that print correctly?

from tidyxl.

stla avatar stla commented on August 16, 2024

No, there's the same issue in the cells. For example "é" and "µ" below.

> x$data$Sheet1[,"character"]
# A tibble: 8 × 1
  character
      <chr>
1         A
2         B
3        é
4      <NA>
5      <NA>
6        µ
7      <NA>
8      <NA>

from tidyxl.

nacnudus avatar nacnudus commented on August 16, 2024

Please can you test the latest version.

from tidyxl.

stla avatar stla commented on August 16, 2024

Looks perfect 👍

json <- jsonlite::fromJSON("{\"a\":[\"µ\",null,2],\"é\":[\"c\",4]}", simplifyVector=FALSE)
jsoncomments <- jsonlite::fromJSON("{\"a\":[\"Stéphane\",null,null],\"é\":[null,\"bye\"]}", simplifyVector=FALSE)

library(openxlsx)

headerStyle <- createStyle(textDecoration = "Bold", border="Bottom")

wb <- createWorkbook()
addWorksheet(wb=wb, sheetName = "Sheet1")
addStyle(wb, sheet="Sheet1", style=headerStyle, rows=1, cols=seq_along(json))
for(j in seq_along(json)){
  writeData(wb, sheet="Sheet1", x=names(json)[j], startRow=1L, startCol=j)
  column <- json[[j]]
  comments <- jsoncomments[[j]]
  for(i in seq_along(column)){
    writeData(wb, sheet="Sheet1", x=column[[i]], startRow=i+1L, startCol=j)
    if(!is.null(comment <- comments[[i]])){
      writeComment(wb, sheet="Sheet1", col=j, row=i+1L, 
                   comment=createComment(comment=comment, visible=FALSE))
    }
  }
}

saveWorkbook(wb, "test001.xlsx", overwrite = TRUE) 

txl <- tidyxl::tidy_xlsx("test001.xlsx", sheets=1)
> txl$data$Sheet1[,c("character","comment")]
  character  comment
1         a     <NA>
2         é     <NA>
3         µ Stéphane
4         c     <NA>
5      <NA>      bye
6      <NA>     <NA>

from tidyxl.

nacnudus avatar nacnudus commented on August 16, 2024

Thanks!

from tidyxl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.