Load Excel Data Into Matrix

Function LoadExcelNumericDataAsMatrix(pathName, fileName, worksheetName, startCell, endCell)
    String pathName                     // Name of Igor symbolic path or "" to get dialog
    String fileName                         // Name of file to load or "" to get dialog
    String worksheetName
    String startCell                            // e.g., "B1"
    String endCell                          // e.g., "J100"
    if ((strlen(pathName)==0) || (strlen(fileName)==0))
        // Display dialog looking for file.
        Variable refNum
        String filters = "Excel Files (*.xls,*.xlsx,*.xlsm):.xls,.xlsx,.xlsm;"
        filters += "All Files:.*;"
        Open/D/R/P=$pathName /F=filters refNum as fileName
        fileName = S_fileName               // S_fileName is set by Open/D
        if (strlen(fileName) == 0)          // User cancelled?
            return -2

    // Load row 1 into numeric waves
    XLLoadWave/S=worksheetName/R=($startCell,$endCell)/COLT="N"/O/V=0/K=0/Q fileName
    if (V_flag == 0)
        return -1           // User cancelled

    String names = S_waveNames          // S_waveNames is created by XLLoadWave
    String nameOut = UniqueName("Matrix", 1, 0)
    Concatenate /KILL /O names, $nameOut    // Create matrix and kill 1D waves
    Printf "Created numeric matrix wave %s containing cells %s to %s in worksheet \"%s\"\r", nameOut, startCell, endCell, worksheetName

    return 0            // Success




Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More