Make persistant changes in executable app by user

1 次查看(过去 30 天)
Hi!
I am creating a stand-alone application which gets an excel sheet uploaded, and displays data based on it.
Thing is, a specific user will probably use the app for the same file many times, so I would like him to be able to choose a default file which will get uploaded automatically every time he opens the app, until he changes it.
is it possible?
Thank you very much!

回答(2 个)

Amith
Amith 2024-10-13
Hi Net,
It is possible to configure a MATLAB standalone application to use a specific Excel file for its execution. Here's a general approach to achieve this:
Access the Excel File in Your Code: In your MATLAB code, you can specify the path to the Excel file. If the file is included in the same directory as the executable, you can use relative paths.
excelFilePath = fullfile(pwd, 'myExcelFile.xlsx');
data = readtable(excelFilePath);
Check for Updates to the Excel File: If you want the application to use the updated Excel file whenever it is changed, you can implement a check to see if the file has been modified. You can use the dir function to get the file’s modification date.
fileInfo = dir(excelFilePath);
lastModified = fileInfo.datenum;
% Store lastModified and compare in subsequent runs
Hope this helps!

Walter Roberson
Walter Roberson 2024-10-13
You have several possibilities:
  1. Use a search strategy to try to find configuration information. For example use the Windows USERPROFILE environment variable and some specific sub-directory and some specific file relative to that; if the configuration file exists, read it, and otherwise use default values. After the user chooses some location and the location is validated, write the information to to the location of the configuration file. This information will not be erased if the application is uninstalled. Note: for portability, you should use isunix() or ispc() to choose the HOME environment variable instead of USERPROFILE for the case of running on MacOS or Linux
  2. Use getpref() and setpref() to control the saved information. If you do this, then chances are that the information will be erased if the application is uninstalled.
  3. Store the information in some file relative to the application; use ctfroot() to locate the file. If you do this, then chances are that the information will be erased if the application is uninstalled.

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by