title: Reading Excel files with XLConnect returns "Error: InvalidFormatException (Java): Your InputStream was neither an OLE2 stream, nor an OOXML stream"
body: <p>I am trying to read the contents of a score of Excel files into R with XLConnect. This is a simplified version of my code:</p>
  
  <pre><code># point to a folder
  path &lt;- "/path/to/folder"
  
  # get all the Excel files in that folder
  files &lt;- list.files(path, pattern = "*.xlsx")
  
  # create an empty data frame
  dat &lt;- data.frame(var.1 = character(), var.2 = numeric())
  
  # load XLConnect
  library("XLConnect")
  
  # loop over the files
  for (i in seq_along(files)) {
      # read each Excel file
      wb &lt;- loadWorkbook(paste(pfad, files[i], sep = "/"))
      # fill the data frame with data from the Excel file
      dat[i, 1:2] &lt;- readWorksheet(wb, "Table1", startRow = 1, startCol = 1, endRow = 2, endCol = 1, header = FALSE)
      rm(wb)
  }
  </code></pre>
  
  <p>I can read in a single file when I specify it with <code>loadWorkbook(paste(pfad, files[1], sep = "/"))</code>, but when I loop over the file list with <code>files[i]</code>, the code inside the for-loop returns the following error:</p>
  
  <pre><code>Error: InvalidFormatException (Java):
      Your InputStream was neither an OLE2 stream, nor an OOXML stream
  </code></pre>
  
  <p>What am I doing wrong?</p>