xlswrite error; not working entirely or throwing up an error
5 views (last 30 days)
Show older comments
Teshan Rezel
on 18 Jan 2021
Commented: Teshan Rezel
on 19 Jan 2021
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
0 Comments
Accepted Answer
Walter Roberson
on 18 Jan 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 Comments
Walter Roberson
on 18 Jan 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?
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!