JanMarvin / openxlsx2

openxlsx2 - read, write and modify xlsx files
https://janmarvin.github.io/openxlsx2/
Other
120 stars 11 forks source link

wb_load fails #261

Closed sigbertklinke closed 2 years ago

sigbertklinke commented 2 years ago

Hi,

the following MWE fails

library("magrittr")
library("openxlsx2")
who <- c("Emma", "Charlotte", "Amelia", "Ava", "Sophia")
for (i in who) {
#  browser()
  file  <- paste0(substr(i, 1, 1), ".xlsx")
  message(file)
  wb    <- if (!file.exists(file)) wb_load("Vorlage0.xlsx") else wb_load(file)
  wb$clone_worksheet("Vorlage", i)
  wb$add_data(x = i, startCol = 2, startRow = 1)
  wb$save(file)
}

with a error message when calling wb_load(file)

E.xlsx
C.xlsx
A.xlsx
A.xlsx
Fehler in names(z) <- as.character(nam) : 
  Attribut 'names' [3] muss dieselbe Länge haben wie der Vektor [1]

Vorlage0.xlsx

JanMarvin commented 2 years ago

Hi @sigbertklinke , confirmed the bug. It's caused by the headerfooter logic. Initially we read the file "Vorlage0.xlsx", when saving it and trying to read it again, we fail:

nam
[1] "L" "C" "R"
z
[1] "&amp;&quot;Times New Roman,Standard&quot;&amp;12&amp;A"
JanMarvin commented 2 years ago

Pushed a fix to #262 Previously exported files are indeed broken, thanks for the report! Your file has only a center entry in header and footer (visible in print preview in LibreOffice). Our export for this type of files was broken.

JanMarvin commented 2 years ago

While we could offer an option to skip the imports of header and footer to read our own broken files, we are still in development, therefore I decided that I don't care to much.