필터 지우기
필터 지우기

How can I send a file via Web Application

조회 수: 52 (최근 30일)
Morteza
Morteza 2018년 10월 21일
댓글: Osborn 2024년 1월 30일
Hi I deployed a web application. After analyzing data imported by user through web browser, I want to send results as an excel file that can be downloaded by user. How should I do that?

채택된 답변

Kojiro Saito
Kojiro Saito 2018년 10월 21일
Users can upload their files by uigetfile and download result by uiputfile. Please keep in mind that uigetfile and uiputfile are supported in WebApps from R2018b.
The following examples can import users' uploaded CSV file and download Excel file. The downloaded file will be found browser's download folder (for example, if Windows, C:\Users\USERNAME\Downloads)
uigetfile example:
% Button pushed function: UploadButton
function UploadButtonPushed(app, event)
[file, path] = uigetfile({'*.csv*'}, 'File Selector', 'MultiSelect', 'on');
if isequal(file,0)
disp('Canceled')
else
% Read input file
inpuFilePath = fullfile(path,file);
tbl = readtable(inpuFilePath);
% Do some calculation
app.resultTbl = table;
app.resultTbl.col1 = tbl.col1 + tbl.col2 + tbl.col3;
end
end
uiputfile example:
% Button pushed function: DownloadButton
function DownloadButtonPushed(app, event)
[file,path] = uiputfile('results.xlsx');
resultFilePath = fullfile(path,file);
writetable(app.resultTbl, resultFilePath)
end
Also, I've attached sample mlapp file and csv file for this demo. Please see Sample_mlapp.zip. If compiled as a WebApps, the app would look like this.
Users can download results.xlsx into their machine.
  댓글 수: 13
Yuhao Sun
Yuhao Sun 2020년 8월 26일
it seems like the uigetdir cannot be supported in web apps. You should show a notification if we use this function when the web app is complied.
Cathie Kessler
Cathie Kessler 2021년 1월 23일
편집: Cathie Kessler 2021년 1월 25일
Has this been resolved? I believe I am experiencing the exact same issue.
I'm not reading; only writing to an Excel (or .csv, if I have to) file. It works perfectly as an app on my computer, but when deployed, I get the "Starting download for test1.xls" message in log, but never receive a file in my Downloads directory.
I'm using writematrix, rather than writetable, but otherwise, my script looks much like the uiputfile example, above.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Roberto M Sanchez
Roberto M Sanchez 2019년 12월 3일
Hello,
This theath has show quite well how to download an excel table using the command writetable. My problem is that I have generated a pdf report with reportgenerator and I want use saveas instead of writetable. But saveas is not supported in webapps.
How can I send the pdf report to the user?.
Thanks.
  댓글 수: 3
Alessandro
Alessandro 2023년 2월 27일
You basically "saved my life"!!!!! Great!
Osborn
Osborn 2024년 1월 30일
@Hunter Casillas's solution works great for non-Excel files. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by