xlswrite - Errors all the time

10 views (last 30 days)
Céline Bachelier
Céline Bachelier on 13 May 2014
Commented: Céline Bachelier on 14 May 2014
Hello,
using xlswrite, and within changing anythig, i have this both error:
% Error using xlswrite (line 220) Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: Microsoft Excel ne peut accéder au fichier « N:\CELINE_B\MIO\13_TRANSMED\DATA\DATA_SEA_KEEPER\FINAL_DATA_2005\MD_2005_02_air_sea.xlsx ». Plusieurs raisons sont possibles :
• Le nom du fichier ou le chemin d'accès n’existe pas. • Ce fichier est actuellement utilisé par un autre programme. • Le classeur que vous essayez d’enregistrer porte le même nom qu’un classeur actuellement ouvert. Help File: xlmain11.chm Help Context ID: 0 %
and
% Error using xlswrite (line 220) The file N:\CELINE_B\MIO\13_TRANSMED\DATA\DATA_SEA_KEEPER\FINAL_DATA_2005\MD_2005_02.xlsx is not writable. It may be locked by another process. %
this is my code for example:
mois_2 = find(data_output_1(:,3)==2); data_mois_2 = data_output_1(mois_2,:);
if exist('data_mois_2','var')==1 xlswrite([path_data_output,racine,'_02','.xlsx'],labels_1); xlswrite([path_data_output,racine,'_02','.xlsx'],data_mois_2,1,'A2'); end
mois_2_all_col = find(data_output_2(:,3)==2); data_mois_2_all_col = data_output_2(mois_2_all_col,:);
if exist('data_mois_2_all_col','var')==1 xlswrite([path_data_output,racine,'_02_air_sea','.xlsx'],labels_2); xlswrite([path_data_output,racine,'_02_air_sea','.xlsx'],data_mois_2_all_col,1,'A2'); end
And i already use the find process runnig to close Excel exe. Maybe my script is dummy. Any idea to stop definitively this kind of errors?
thanks in advance
Regards Céline
  1 Comment
Céline Bachelier
Céline Bachelier on 13 May 2014
I have to run several time the part with the xlswrite for maybe it works !
Céline

Sign in to comment.

Answers (1)

David Sanchez
David Sanchez on 13 May 2014
Try closing your excel document before trying to write on it.
That kind of errors occur when you try to write in a document that is already open.
And make sure that the location where you are trying to write your file is available for writing.
Use fulfile function to build full file name from directories.
help fulfile
doc fulfile
  1 Comment
Céline Bachelier
Céline Bachelier on 14 May 2014
Hello,
Thanks to your response. Any excel document was open. And I process one of your Matlab utilities (find_running_process.m):
% find_running_process.m % Finds out if a process is running. % Let's you monitor the process until it shuts down.
clc; % Clear the command window. workspace; % Make sure the workspace panel is showing. format long g; format compact;
% Execute the system command % tasklist /FI "IMAGENAME eq region_editor.exe" % First define the name of the program we're looking for. % You can run it then execute "tasklist" in a % CMD console window if you don't know the exact name. taskToLookFor = 'Excel.exe'; % Now make up the command line with the proper argument % that will find only the process we are looking for. commandLine = sprintf('tasklist /FI "IMAGENAME eq %s"', taskToLookFor); % Now execute that command line and accept the result into "result". [status, result] = system(commandLine); % Look for our program's name in the result variable. itIsRunning = strfind(lower(result), lower(taskToLookFor)); if itIsRunning message = sprintf('%s is running.', taskToLookFor); uiwait(helpdlg(message)); else message = sprintf('%s is not running.', taskToLookFor); uiwait(helpdlg(message)); return; % Nothing else to do. end
message = sprintf('Do you want to monitor it until it finishes?'); button = questdlg(message, 'Wait for shutdown?', 'Yes', 'No', 'Yes'); drawnow; % Refresh screen to get rid of dialog box remnants. if strcmpi(button, 'No') return; end
% Go into a loop waiting for it to finish. maxChecks = 10; % Max seconds to wait before exiting - a failsafe. numberOfChecks = 1; while itIsRunning && numberOfChecks < maxChecks % Now execute that command line and accept the result into "result". [status, result] = system(commandLine); % Look for our program's name in the result variable. itIsRunning = strfind(lower(result), lower(taskToLookFor)); if itIsRunning message = sprintf('%s is still running after %d seconds.\n',... taskToLookFor, numberOfChecks); fprintf('%s', message); else message = sprintf('%s is not running anymore.\n', taskToLookFor); fprintf('%s', message); uiwait(helpdlg(message)); break; % Exit loop. end pause(1); % Wait a second before checking again. numberOfChecks = numberOfChecks + 1; end msgbox('Done with demo!');
..... Nothing was open after this run. And i think that the location where i'm trying to write is available. What do you mean by available exactly?
I tried fullfile to generate my path, i met the same error.
If somebody has an idea.
Thanks in advance
Best regards
Céline

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!