Reads and writes Excel files.


x = spreadSheetReadM(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.


x (matrix) – numbers read from Excel.


Basic Example

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

x = spreadSheetReadM("myfile.xlsx");

Read From a Range

x = spreadSheetReadM("myfile.xlsx", "B2:D110");

Specify Path and Sheet Number

x = spreadSheetReadM("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 spreadSheetReadM() 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 = spreadSheetReadM("nonexistent_file.xlsx");
    // Turn error trapping on
    trap 1;
    x = spreadSheetReadM("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;