Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //open file
- //init wb
- //init ws
- let rec row_array ws row_num =
- match ws.Rows[row_num] with
- if row_num <= ws.Rows.Length then
- ws.Range("A"+char(row_num)).Value
- |::ws.Range("B"+char(row_num)).Value
- |::ws.Range("C"+char(row_num)).Value
- |::ws.Range("D"+char(row_num)).Value
- |::ws.Range("E"+char(row_num)).Value
- |::[]::(row_array ws (row_num+1))
- else
- []
- let sortedList this_array =
- List.sortBy(fun elem -> elem[1]) this_array
- let merge_rows x y tail func=
- let [a, b, c, d, e] = x
- let [a1, b1, d1, c1, e1] = y
- if a==a1 then
- [a, b, (c+c1), ((c*d+c1*d1)/(e+e1)), (e+e1)]::(func tail)
- else
- [a, b, c, d, e]:: (func ([a1, b1, d1, c1, e1]::tail)
- let merge_last_two_rows x y =
- let [a, b, c, d, e] = x
- let [a1, b1, d1, c1, e1] = y
- if a==a1 then
- [a, b, (c+c1), ((c*d+c1*d1)/(e+e1)), (e+e1)]::[]
- else
- [a, b, c, d, e]::[a1, b1, d1, c1, e1]::[]
- let rec average_prices sorted_list =
- match sorted_list with
- |x::y::tail ->
- merge_rows x y tail average_prices
- |x::y ->
- merge_last_two_rows x y
- let ready_item_array =
- let array = row_array ws 2|> sorted_list|> average_prices
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement