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

write.xlsx(): [Content_Types.xml] file contains reference to /xl/drawings/drawing1.xml, but not the file, which creates problems with openpyxl #429

Open
xjlc opened this issue May 11, 2023 · 1 comment

Comments

@xjlc
Copy link

xjlc commented May 11, 2023

Describe the bug
An Excel file written by openxlsx::write.xlsx() contained a reference (in [Content_Types.xml]) to a nonexistent file (/xl/drawings/drawing1.xml). When trying to import this file into PsychoPy (depending on openpyxl), an error was raised:
KeyError: „There is no item named ‚xl/drawings/drawing1.xml‘ in the archive“

To Reproduce
Not sure if this is generally reproducible. It is with my current setup. Here is the R code:

library(tidyverse)

designDir <- "."

base <- expand.grid(
  iV1=c("A", "B"),
  iV2=c("c", "ic"),
  list=1:2)

# compute different orders (nested: we want iV2 to vary within iV1)
for (i in 1:8) {
  # thisbase: list 1 for 1..4, list 2 for 5..8
  thisbase <- base %>% filter(base$list==base$list[i])
  switch( (i-1)%%4+1, # this evalutes to 1,2,3,4,1,2,3,4
    {blockdesign <- thisbase %>% arrange(iV1, iV2)},            #1
    {blockdesign <- thisbase %>% arrange(desc(iV1), iV2)},      #2
    {blockdesign <- thisbase %>% arrange(iV1, desc(iV2))},      #3
    {blockdesign <- thisbase %>% arrange(desc(iV1), desc(iV2))} #4
  )
  # for convenience, compute condsfile (to specify inner loop conditions file in PsychoPy)
  blockdesign <- blockdesign %>%
    mutate(condsfile = paste0("Exp4_", iV1, "_", iV2, "_", list, ".xlsx"))
  # write balance file
  blockfilename <- file.path(designDir, paste0("balance_", i, ".xlsx"))
  openxlsx::write.xlsx(blockdesign, file=blockfilename)
 }

Expected behavior
I guess that either the referenced file drawing1.xml should be present or the reference to it should be absent.

I am a big fan of openxlsx and have never encountered any problems, but this one seems weird.

Example files
balance_1.xlsx

Additional context
I'm using version 4.2.5.2.
The directory I'm writing the files to is under git control.

@ScaonE
Copy link

ScaonE commented Oct 26, 2023

Having the same issue on my side.
Tried the fixes suggested here without success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants