xlswrite error; not working entirely or throwing up an error
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2021-1-18
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 个评论
Walter Roberson
2021-1-18
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!