I need to close excel file before importing data

11 ビュー (過去 30 日間)
Roohollah
Roohollah 2023 年 10 月 12 日
コメント済み: Roohollah 2023 年 10 月 13 日
I recently started using MATLAB R2023a.
When I use functions such as xlsread or readtable to read data from an excel file, the file must be closed before calling function.
Previously, when I was using MATLAB R2019 or older versions, this was not the case.
Can this issue be fixed?
  3 件のコメント
Jon
Jon 2023 年 10 月 12 日
編集済み: Jon 2023 年 10 月 12 日
I am using R2023b on a Windows machine.
For me this behavior seems to depend upon the location of the Excel file. When I have the current MATLAB directory and the .xlsx file both in, for example, in C:\TEMP\Matlab then I can use readtable successfully whether the .xlsx file is open or not. When I put exactly the same .xlsx file in my One Drive folder, I can use readtable when the file is closed but if it is open then I get the error :
Error using readtable
Unable to open file 'C:\Users\jxxx.xxx\OneDrive - xxxx\myfile.xlsx'
as a workbook. Check that the file exists, read access is available, and the file is a
valid spreadsheet file.
When I look at the permissions for the file in the One Drive folder they seem to be the same as when it is in the C:\Temp\Matlab location, but somehow there must be some difference.
I would also like to know if there is a solution for this, as it can be annoying if I just want to read the file and I forget to close it. At the least, it would be nice if I could get it to throw an error that indicated that the problem was that the file was open, rather than the more obscure error that it now reports
Roohollah
Roohollah 2023 年 10 月 13 日
I checked it and that is the problem.
When I work with files on OneDrive, they have to be closed.
If you could find any solution, please let me know.

サインインしてコメントする。

回答 (2 件)

Cris LaPierre
Cris LaPierre 2023 年 10 月 12 日
Suggestions and suspected bugs can be reported here: https://www.mathworks.com/support/contact_us.html

Jon
Jon 2023 年 10 月 13 日
I looked a little more on MATLAB answers and saw that this issue was previously described, and is a known issue for the Mathworks developers. Please see https://www.mathworks.com/matlabcentral/answers/514294-why-does-readtable-fail-to-read-a-file-from-onedrive?s_tid=answers_rc1-2_p2_MLTfor more info.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by