readtable can read Excel XLS but not XLSX on OneDrive?

9 views (last 30 days)
Hello!
Unable to open file 'C:\Users\juans\OneDrive\Juan\Matlab\Book5.xlsx' as a workbook. Check that the file exists, read access is available, and the file is a valid spreadsheet file.
A while ago, it was identified that there was an issue with OneDrive blocking Excel files, and you have to close the file on Excel in order for MATLAB to open it, which is very inconvenient for the workflow. Another workaround I found is to use XLS, which is also not always a good solution. I could not find whether this issue has been solved.
What is the current status of this issue? (I have 2023a)
Cheers!

Answers (1)

Pavan Sahith
Pavan Sahith on 19 Jun 2024
Edited: Pavan Sahith on 19 Jun 2024
Hello Juan,
I see that you encountering an issue when trying to read an Excel (.xlsx) file especially when the file is open in the background.
I assume you are using the readtable function in MATLAB for the above task.
I experienced the same issue in MATLAB R2024a. After researching similar MATLAB answers, I found that the problem is likely related to OneDrive locking the file for editing purposes.
OneDrive syncs files to the cloud when they are updated, which can cause the files to be locked temporarily, preventing write operations. Disabling OneDrive syncing can resolve this issue.
Here are a few workarounds that worked for me, which may also be useful for you:
  1. If the file is accessible on a HTTPS location, readtable can be used directly on the HTTPS path.
  2. The file can be moved or copied to a local directory, ensuring OneDrive does not lock it.
  3. if you are trying to write to the file, writing to a temporary location, then moving that file when you're done processing.
you can refer to the following MathWorks documentation which might help you
also attaching the similar MATLAB answers for your reference
I hope this information helps you move forward.
  1 Comment
Juan Saenz-Diez
Juan Saenz-Diez on 21 Jun 2024
Edited: Juan Saenz-Diez on 21 Jun 2024
Hello Pavan,
Thank you Pavan for your thorough reply. Yes, that's the problem, I am exactly in the same predicament as Jon in answer 1587374. I am going back and forth between the Excel file and the Matlab environment, both in development and in production. Writes are not needed, therefore simply reading from the Excel file would be enough but this is blocked? Why is it that XLSX are blocked but XLS are not? (XLS is another workaround if it does not bother you with other problems.) Is there anybody at Matlab dev team working on how to just read the file?
The HTTPS did not work for me, I got this weird error when reading from the HTTPS location:
"
Warning: The following error was caught while executing 'matlab.io.internal.vfs.stream.RemoteToLocal' class destructor:
Error using rmdir
No directories were removed.
Error in matlab.io.internal.vfs.stream.RemoteToLocal/deleteIfLocalCopy (line 181)
rmdir(localTempDir, 's');
Error in matlab.io.internal.vfs.stream.RemoteToLocal/delete (line 65)
deleteIfLocalCopy(obj);
Error in matlab.io.internal.functions.ExecutableFunction/validateAndExecute (line 69)
end
Error in readtable (line 514)
t = func.validateAndExecute(filename,varargin{:});
> In matlab.io.internal.functions/ExecutableFunction/validateAndExecute (line 69)
In readtable (line 514)
T =
2×1 table
MicrosoftAccountRequiresJavaScriptToSignIn_ThisWebBrowserEither
_____________________________________________________________________________________________________________
{0×0 char }
{'To find out whether your browser supports JavaScript, or to allow scripts, see the browser's online help.'}
"
Besides, would the OneDrive address be stable?
Cheers!
Juan.

Sign in to comment.

Categories

Find more on Environment and Settings 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!