mjul / docjure

Read and write Office documents from Clojure
MIT License
623 stars 129 forks source link

Suggestion - extra indirection level to support stream IO instead of just filenames #1

Closed edgargoncalves closed 8 years ago

edgargoncalves commented 14 years ago

This will be useful for webapps, at least. I currently have the following defined to support this:

(defn load-workbook-from-stream
  "Load an Excel .xls or .xlsx workbook from a stream."
  [in-stream]
  (with-open [stream in-stream]
    (WorkbookFactory/create stream)))

(defn stream-workbook! 
  "Write the workbook into a stream."
  [#^Workbook workbook]
  (assert-type workbook Workbook)
  (with-open [out-stream (ByteArrayOutputStream.)]
    (.write workbook out-stream)
    (ByteArrayInputStream. (.toByteArray out-stream))))
mjul commented 14 years ago

Thanks for the feedback - it is a great idea. Maybe we could do it with a multimethod load-workbook rather than having a -from-stream variant.

Regards, Martin

edgargoncalves commented 14 years ago

For people looking at this thread hoping to use this with Google App Engine: sorry to inform that it will fail, just because creating a blank workbook will fail on (blank-workbook): Uncaught exception from servlet org.apache.poi.POIXMLException: java.security.AccessControlException: access denied (java.io.FilePermission poifiles write) at org.apache.poi.xssf.usermodel.XSSFWorkbook.newPackage(XSSFWorkbook.java:28 1) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:158) at myproject.namespace$blank_workbook.invoke(docs.clj:8)

Feel free to suggest a workaround!

mjul commented 8 years ago

Thanks for your feedback. I am pleased to report that Docjure supports streams as of version 1.9.0.