|
@@ -45,21 +45,26 @@
|
|
(= (max col1 col2) col1) [col2 col1]
|
|
(= (max col1 col2) col1) [col2 col1]
|
|
:else [col1 col2]))
|
|
:else [col1 col2]))
|
|
|
|
|
|
|
|
+(defn range->list
|
|
|
|
+ "Converts two cells (accepting four coordinates) into a list of all the cells in the range between them (inclusively)."
|
|
|
|
+ [col1 row1 col2 row2]
|
|
|
|
+ (let [[start-col end-col] (order-two-cols col1 col2)
|
|
|
|
+ start-row (min row1 row2)
|
|
|
|
+ end-row (max row1 row2)]
|
|
|
|
+ (for [col (take-while #(not= (next-letter end-col) %) (iterate next-letter start-col))
|
|
|
|
+ row (range start-row (inc end-row))]
|
|
|
|
+ {:col col :row row})))
|
|
|
|
+
|
|
; the order goes top to bottom, then left to right - that makes the most sense to me
|
|
; the order goes top to bottom, then left to right - that makes the most sense to me
|
|
; I don't know why a different order would be important, or even in what situation order is important at all
|
|
; I don't know why a different order would be important, or even in what situation order is important at all
|
|
(defn parse-range
|
|
(defn parse-range
|
|
- "Converts a range in \"A1:B2\" notation to a comma-separated list of cells: \"A1,A2,B1,B2\"."
|
|
|
|
|
|
+ "Converts a range in \"A1:B2\" notation to a list of col/row cells: {:col \"A\" :row 1}, etc."
|
|
[range-string]
|
|
[range-string]
|
|
(let [col1 (second (re-find #"\(\s*([A-Z]+)" range-string))
|
|
(let [col1 (second (re-find #"\(\s*([A-Z]+)" range-string))
|
|
col2 (second (re-find #":\s*([A-Z]+)" range-string))
|
|
col2 (second (re-find #":\s*([A-Z]+)" range-string))
|
|
row1 (.parseInt js/window (second (re-find #"([0-9]+)\s*:" range-string)))
|
|
row1 (.parseInt js/window (second (re-find #"([0-9]+)\s*:" range-string)))
|
|
- row2 (.parseInt js/window (second (re-find #"([0-9]+)\s*\)" range-string)))
|
|
|
|
- [start-col end-col] (order-two-cols col1 col2)
|
|
|
|
- start-row (min row1 row2)
|
|
|
|
- end-row (max row1 row2)]
|
|
|
|
- (for [col (take-while #(not= (next-letter end-col) %) (iterate next-letter start-col))
|
|
|
|
- row (range start-row (inc end-row))]
|
|
|
|
- {:col col :row row})))
|
|
|
|
|
|
+ row2 (.parseInt js/window (second (re-find #"([0-9]+)\s*\)" range-string)))]
|
|
|
|
+ (range->list col1 col2 row1 row2)))
|
|
|
|
|
|
(def range->commalist
|
|
(def range->commalist
|
|
"Converts a range in \"A1:B2\" notation to a comma-separated list of cells: \"A1,A2,B1,B2\"."
|
|
"Converts a range in \"A1:B2\" notation to a comma-separated list of cells: \"A1,A2,B1,B2\"."
|