Why do I get the error 'Ensure the file is a valid spreadsheet file and is not password protected.'?

61 views (last 30 days)
I want to create an excel file called 'Results' in the same directory as my matlab file. This is the code I wrote so far:
Result_File='Results.xlsx'; %save result into this excel file
% [a loop is here to obtain 'T']
fid = fopen(Result_File,'w');
writetable(T,Result_File)
when I run it, I get the error:
Error using EXP2_Ver12_Evaluation_of_Meteonorm_simulation (line 105)
Unable to write to file
'\\data-be\data-ti-2019\eit\50_Labore\T016-Photovoltaik_1\06_Projekte\02_Aktiv\2019_Schenker_Storen\DOCS_Hannah\Experiment2\04_Evaluation_of_Meteonorm_simulation\Results.xlsx'.
Ensure the file is a valid spreadsheet file and is not password protected.
I dont understrand how it could be passwprd protected or not valid because my script creates the file that I am writing into.

Accepted Answer

Johannes Hougaard
Johannes Hougaard on 17 Aug 2021
Because you make and open the (empty) file with the fopen call but don't use the file identifier for the writetable (which you shouldn't do).
make sure you have all file identifiers closed (exit MATLAB or call fclose all), delete the Results.xlsx file and re-run the code without fopen
Result_File='Results.xlsx'; %save result into this excel file
% [a loop is here to obtain 'T']
writetable(T,Result_File)

More Answers (0)

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!