Reads and writes Excel files.


sa = spreadSheetReadSA(file[, range[, sheet]])
  • file (string) – name of .xls, or .xlsx file.
  • range (string) – range to read or write; e.g., "A1:B20". Default = "A1".
  • sheet (scalar) – sheet number. Default = 1.

sa (string array) – read from Excel.


Basic Example

Read all contents from the file myfile.xlsx located in your current GAUSS working directory as a string array.

s = spreadSheetReadSA("myfile.xlsx");

Read From a Range

s = spreadSheetReadSA("myfile.xlsx", "B2:D110");

Specify Path and Sheet Number

s = spreadSheetReadSA("C:\\mydata\\myfile.xlsx", "A1", 1);


Windows, Linux and macOS


  1. If range is a null string, then by default the read will begin at cell “A1”.

  2. If spreadSheetReadSA() fails, it will either terminate and print an error message or return a scalar error code, which can be decoded with scalerr(), depending on the state of the trap flag.

    trap 0 print error message and terminate program
    trap 1 return scalar error code
    // Will end the program and print an error message
    x = spreadSheetReadSA("nonexistent_file.xlsx");
    // Turn error trapping on
    trap 1;
    x = spreadSheetReadSA("nonexistent_file.xlsx");
    // Check to see if 'x' is a scalar error code
    if scalmiss(x);
       // Code to handle error case here
    // Turn error trapping off
    trap 0;