Revision 616537343232 () - Diff

Link to this snippet: https://friendpaste.com/wmX89ywgPhdN5hvVBEAbg
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(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)