tomfaulhaber / excel-templates

Create Excel workbooks from Clojure code using templates and plain old data
Eclipse Public License 1.0
152 stars 20 forks source link

Adding a 2nd sheet raise an exception #13

Open shofetim opened 9 years ago

shofetim commented 9 years ago

Using 0.3.0 Using this (simple) template Created with LibreOffice Version: 4.4.2.2

As soon as I add a 2nd named sheet:

(ns bug
  (:require [excel-templates.build :as excel]))

(excel/render-to-file
  "templates/test.xlsx"
  "/tmp/out.xlsx"
  {"Sheet1" [{:sheet-name "Foo Squares"
               3 [[1 1] [2 4] [3 9]]}
              {:sheet-name "Bar Squares"
               3 [[5 25] [6 36]]}]})

The following error is raised:

java.io.IOException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /xl/worksheets/_rels/sheet2.xml.rels does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]
        at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:69)
        at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:263)
        at sun.reflect.GeneratedConstructorAccessor63.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at clojure.lang.Reflector.invokeConstructor(Reflector.java:180)
        at excel_templates.build$render_to_file.invoke(build.clj:401)
        at bug$eval19263.invoke(form-init533457289181712521.clj:1)
        at clojure.lang.Compiler.eval(Compiler.java:6703)
        at clojure.lang.Compiler.eval(Compiler.java:6666)
        at clojure.core$eval.invoke(core.clj:2927)
        at clojure.main$repl$read_eval_print__6625$fn__6628.invoke(main.clj:239)
        at clojure.main$repl$read_eval_print__6625.invoke(main.clj:239)
        at clojure.main$repl$fn__6634.invoke(main.clj:257)
        at clojure.main$repl.doInvoke(main.clj:257)
        at clojure.lang.RestFn.invoke(RestFn.java:1523)
        at clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__10024.invoke(interruptible_eval.clj:67)
        at clojure.lang.AFn.applyToHelper(AFn.java:152)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.core$apply.invoke(core.clj:624)
        at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:51)
        at clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__10066$fn__10069.invoke(interruptible_eval.clj:183)
        at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__10059.invoke(interruptible_eval.clj:152)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

Possibly related to #4 and #7

tomfaulhaber commented 9 years ago

Yup, I can reproduce that here. I'll take a look. Thanks for the nice bug report.

shofetim commented 9 years ago

I've been playing with it abit, I think the problem may be something in LibreOffice, everything seems to work if the template was created by MS Excel 2007

tomfaulhaber commented 9 years ago

That was going to be my first guess. This is interesting, because I think it's actually on the 2nd pass that it fails. That is, we read the template, write to an intermediate with the first result sheet and then try to read the intermediate back, and that's when it breaks (I think).

tomfaulhaber commented 9 years ago

The problem here is worse that reported. I cannot open any spreadsheet that's based on a LibreOffice template in either Excel or Libre Office. If I comment out the second sheet, the program completes without errors, but the resulting spreadsheet makes Excel throw errors on open and is empty in Libre Office.

shofetim commented 9 years ago

I'm unsure what the underlying bug with LibreOffice is, but FWIW I was able to create the templates with Google Sheets, exported as MS Excel 2011. Which is much more convenient then running a VM to get Excel setup.

tomfaulhaber commented 8 years ago

There's no bug in LibreOffice here, I don't think. I think that the problem is in POI and the way we use it. When we transform the workbook, we add a drawing where there was none before. I am going to start by resolving #26 and updating the program to use the new .getDrawingPatriarch method to see if that solves this problem.

Therefore, this issue depends on #26.