Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Created January 28, 2020 20:16
Show Gist options
  • Save aarkerio/b1949a5d1e44e4add50335e62a96e2b2 to your computer and use it in GitHub Desktop.
Save aarkerio/b1949a5d1e44e4add50335e62a96e2b2 to your computer and use it in GitHub Desktop.
Create a LibreOffice text ODF file
(ns clj-odf.core
(:import java.net.URI
org.odftoolkit.simple.TextDocument
org.odftoolkit.simple.table.Cell
org.odftoolkit.simple.table.Table
org.odftoolkit.simple.text.list.List))
(defn generate-odf [filename]
(let [outputOdt (TextDocument/newTextDocument)
uri (URI. "/home/manuel/Documents/lisplogo_fancy_256.png")
items (into-array String ["Primer Asunto" "Segundo punto" "Tercer negocio" "Too long list"])]
(try
(println "Generating ODF file")
(.addParagraph outputOdt "Hello World, taradazo Hello Simple ODF!")
(.newImage outputOdt uri)
(.addParagraph outputOdt "Hello World, taradazo Hello Simple ODF AFTER IMAGE!")
(.addParagraph outputOdt "The following is a list.")
(.addItems (.addList outputOdt) items)
(.setStringValue (.getCellByPosition (.addTable outputOdt 2 2) 0 1) "I'm in the table!")
(.save outputOdt filename)
(catch Exception e (str "ERROR: unable to create output file: " (.getMessage e))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment