Text_to_excel Revision 616537343232 (Tue Jun 09 2009 at 14:57) - Diff Link to this snippet: https://friendpaste.com/wmX89ywgPhdN5hvVBEAbg Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(import '(javax.swing JFrame JMenuItem JFileChooser) '(javax.swing.text MaskFormatter) '(java.awt.event ActionListener) '(javax.swing.event MenuListener) '(java.awt GridLayout Component FileDialog) '(com.jacob.com Dispatch ComThread))(use 'clojure.contrib.duck-streams)(defmacro add-item-action [item action] "add a action as a listener listener to a item" `(.addActionListener ~item (proxy [ActionListener] [] (~'actionPerformed [~'evt] ~@action))))(def xel (new Dispatch "Excel.Application"))(def ws (ref " "))(def adir (ref " "))(defn get-workbooks [xel m-xel] (.. Dispatch (get xel m-xel)(toDispatch)))(comment (defn get-workbooks-plus [xel m-xel get-plus] (.. Dispatch (get xel m-xel get-plus)(toDispatch))))(defn call-xel [get-workbook action location](.. Dispatch (call get-workbook action location)(toDispatch)));(def adir (ref " " ))(defn foll-fn [adir](let [cal-excel (-> xel (get-workbooks "Workbooks") (call-xel "Open" @adir)) get-workbook (get-workbooks cal-excel "Worksheets")] (dosync (ref-set ws(-> get-workbook (call-xel "Item" 1)(Dispatch/put "Visible" true))))))(defn print-on-cells [alon i k](let [m (.. Dispatch (call ws "Cells" i (+ 2 k))(toDispatch))](if (seq alon)(if (< k 8)(do (Dispatch/put m "Value" (str (first alon)))(print-on-cells (rest alon) i (inc k)))(print-on-cells (rest alon) (inc i) 1))(do (Dispatch/put xel "Visible" true)(. Dispatch call m "Close" false)(. Dispatch call xel "Quit")(ComThread/Release)))));(def mooo (dosync (ref-set adir "C:\\clojure\\waterfront\\cello" )));(foll-fn (dosync (ref-set adir mooo )))(defn process-file [file-name](map #(-> % second Double/parseDouble)(re-seq #"=>\s[A-Z\s]*(\-?[0-9]+\.[0-9]+)"(slurp* file-name))))(defn create-board-gui [] "Office Utility" (let [frame (javax.swing.JFrame. "Notepad to Excel converter") bar (javax.swing.JMenuBar.) dni-item (JMenuItem. "DNI File") ost-item (JMenuItem. "OST File") file-menu (javax.swing.JMenu. "File") file-chooser (javax.swing.JFileChooser. ".")](add-item-action dni-item (do (.showOpenDialog file-chooser frame) (let [file (.getSelectedFile file-chooser)] (when file (-> file process-file (print-on-cells 37 1))))))(add-item-action ost-item (do (.showOpenDialog file-chooser frame) (let [file (.getSelectedFile file-chooser)] (when file (foll-fn (dosync (ref-set adir file))))))) (doto file-menu (.add dni-item) (.add ost-item)) (doto file-chooser (.setDialogTitle "t")) (doto bar (.add file-menu))(doto frame (.setLayout (java.awt.GridLayout. 9 1)) (.setSize 300 300) (.setJMenuBar bar) (.setVisible true))));(create-board-gui)