2 Basic Example
2.1 Generate a xlsx file
(write-xlsx |
"basic.xlsx" |
(lambda () |
(add-data-sheet "Sheet1" '(("month1" "month2" "month3" "month4" "real"))) |
|
(add-data-sheet "Sheet2" '((201601 100 110 1110 6.9))))) |
1. All operations in write-xlsx’s lambda scope.
2. Specify file name, sheet name, have same count’s list data, done.
2.2 Read a xlsx file
(read-xlsx |
"basic_write.xlsx" |
(lambda () |
(check-equal? (get-sheet-name-list) '("Sheet1" "Sheet2")) |
|
(with-sheet-ref |
0 |
(lambda () |
(check-equal? (get-row 1) '("month1" "month2" "month3" "month4" "real")))) |
|
(with-sheet-ref |
1 |
(lambda () |
(check-equal? (get-row 1) '(201601 100 110 1110 6.9)))))) |
Navigate to a specific sheet have two ways: use index or name
(with-sheet-ref |
sheet_index |
(lambda () ...)) |
(with-sheet-name |
sheet_name |
(lambda () ...)) |
2.3 Read a xlsx file, modify something and Write back
(read-and-write-xlsx |
basic_write_file |
basic_read_and_write_file |
(lambda () |
(check-equal? (get-sheet-name-list) '("Sheet1" "Sheet2")) |
|
(with-sheet-ref |
0 |
(lambda () |
(set-cell-value! "B1" "John") |
(check-equal? (get-row 1) '("month1" "John" "month3" "month4" "real")))) |
|
(with-sheet-ref |
1 |
(lambda () |
(check-equal? (get-row 1) '(201601 100 110 1110 6.9)))) |
)) |
The first arg is read file, second is the write back file, these two can be a same file, if you want to replace the oringinal.