On this page:
with-input-from-xlsx-file
load-sheet
get-sheet-names
get-cell-value
get-cell-formula
oa_  date_  number->date
get-sheet-dimension
get-sheet-rows
sheet-name-rows
sheet-ref-rows

2 Read

read from a .xlsx file.

you can get a specific cell’s value or loop for the whole sheet’s rows.

 (require simple-xlsx) package: simple-xlsx

there is also a complete read and write example on github:includedin the source.

procedure

(with-input-from-xlsx-file xlsx_file_path    
  user-proc)  void?
  xlsx_file_path : (path-string?)
  user-proc : (-> xlsx_handler void?)
read xlsx’s main outer func, all read assosiated action is include in user-proc.

procedure

(load-sheet sheet_name xlsx_handler)  void?

  sheet_name : (string?)
  xlsx_handler : (xlsx_handler)
load specified sheet by sheet name. must first called before other func, because any other func is based on specified sheet.

procedure

(get-sheet-names xlsx_handler)  list?

  xlsx_handler : (xlsx_handler)
get sheet names.

procedure

(get-cell-value cell_axis xlsx_handler)  any

  cell_axis : (string?)
  xlsx_handler : (xlsx_handler)
get cell value through cell’s axis. cell axis: A1 B2 C3...

procedure

(get-cell-formula cell_axis xlsx_handler)  string?

  cell_axis : (string?)
  xlsx_handler : (xlsx_handler)
get cell formula. If no formula for the cell, will return an empty string

Limitations: currently does not support array or shared formulae

cell axis: A1 B2 C3...

procedure

(oa_date_number->date oa_date_number)  date?

  oa_date_number : (number?)
if knows cell’s type is date, can use this function to convert to racket date? type. if not convert, xlsx’s date type just is a number, like 43361.

this function can convert number to a date? with precision to day only, the hour, minute and seconds set to 0.

(oa_date_number->date 43359.1212121) to a date is 2018-9-16 00:00:00.

procedure

(get-sheet-dimension xlsx_handler)  pair?

  xlsx_handler : (xlsx_handler)
get current sheet’s dimension, (cons row col) like (1 . 4)

procedure

(get-sheet-rows xlsx_handler)  list?

  xlsx_handler : (xlsx_handler)
get-sheet-rows get all rows from current loaded sheet

procedure

(sheet-name-rows xlsx_file_path sheet_name)  list?

  xlsx_file_path : (path-string?)
  sheet_name : (string?)
if, only if just want get a specific sheet name’s data, no other operations on the xlsx file.

this is the most simple func to get xlsx data.

procedure

(sheet-ref-rows xlsx_file_path sheet_index)  list?

  xlsx_file_path : (path-string?)
  sheet_index : (exact-nonnegative-integer?)
same as sheet-name-rows, use sheet index to specify sheet.