excelmatlabmatlab-gui

Read data from excel to table in MATLAB App Designer


Good evening I am trying to develop a MATLAB GUI where the user can either input the data manually in a table or attach an excel folder, which will copy the data in the excel sheet in the table. My lines of code are

function AttachExcelFolderButtonPushed(app, event)
            [filename pathname]=uigetfile({'*.xlsx'},'File Selector');
            text = readtable(filename, "Sheet",1);
            app.UITable.Data = text;
        end

I get the following error:

Error using readtable (line 223) Unable to open file 'Book1.xlsx' as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.

Please help Note: I am a newbie Thank you


Solution

  • My guess is that you don't have the file you want on the path. Try this line:

    text = readtable([pathnaem filename], "Sheet",1);
    

    This will use the entire path of the file to find it. Otherwise MATLAB will only look for files currently on the path.