Commit 03465fc2 authored by Carlos Ungil's avatar Carlos Ungil

na-string support, sqlite example

parent 041b3362
......@@ -97,14 +97,16 @@ A numeric id or name is required unless the file contains a single worksheet."
(date? (excel-date (parse-integer value)))
(t (read-from-string value))))))))))
(defun as-matrix (xlsx)
(defun as-matrix (xlsx &optional na-string)
"Creates an array from a list of cells of the form ((:A . 1) . 42)
Empty columns or rows are ignored (column and row names are returned as additional values)."
Empty columns or rows are ignored (column and row names are returned as additional values).
When a value is equal to na-string, nil is returned instead."
(declare (optimize speed))
(let* ((refs (mapcar #'first xlsx))
(cols (sort (remove-duplicates (mapcar #'car refs)) #'string< :key (lambda (x) (format nil "~3@A" x))))
(rows (sort (remove-duplicates (mapcar #'cdr refs)) #'<))
(output (make-array (list (length rows) (length cols)) :initial-element nil)))
(loop for ((col . row) . val) in xlsx
do (setf (aref output (the fixnum (position row rows)) (the fixnum (position col cols))) val))
do (setf (aref output (the fixnum (position row rows)) (the fixnum (position col cols)) )
(if (equal val na-string) nil val)))
(values output cols rows)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment