xlswrite error; not working entirely or throwing up an error

3 visualizaciones (últimos 30 días)
Hi All,
I'm getting the following error when using xlswrite:
Error using xlswrite (line 224)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: Microsoft Excel cannot access the file 'D:\CAF\ash test march 2020\Test Piece 6\'. There are several possible reasons:
The file name or path does not exist.
The file is being used by another program.
The workbook you are trying to save has the same name as a currently open workbook.
Help File: xlmain11.chm
Help Context ID: 0
The code is as follows:
filename = [RawImages '\' Sample '\' Sample]; %Creating the filename to put the excel file in the appropriate folder
if isempty(TestPieceName)
xlswrite(filename, TestPiece);
else
xlswrite(filename, TestPiece, TestPieceName);
end
I find that if I change the filename statement to:
filename = [RawImages '\' Sample]; %Creating the filename to put the excel file in the appropriate folder
then it eliminates the error, but now xlswrite will simply run but not create the files. I've tried making "desktop" directories in system32 and 64 as per other suggestions on the site, and checked that the license for Office is working.
Any ideas how to fix this please?
Thanks

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de En. de 2021
Your variable Sample is empty, so when you construct
filename = [RawImages '\' Sample '\' Sample]
you are getting the result
D:\CAF\ash test march 2020\Test Piece 6\
based upon RawImages being D:\CAF\ash test march 2020\Test Piece 6 to which you append \ then empty then \ then empty, leaving you with something ending in \ which is not a valid file name to write to.
If Sample were not empty, then it would appear twice in D:\CAF\ash test march 2020\Test Piece 6\ which does not happen.
  7 comentarios
Walter Roberson
Walter Roberson el 18 de En. de 2021
Perhaps
rd = RawImages;
if ~isdir(rd); mkdir(rd); end
sdir = fullfile(rd, Sample);
if ~isdir(sdir); mkdir(sdir); end
filename = fullfile(sdir, [Sample '.xlsx']);
What is your current error message?
Teshan Rezel
Teshan Rezel el 19 de En. de 2021
that's done the trick, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by