Excelシート上のデータが読み込めない
Show older comments
以下のコードを用いて,複数のシートを持つExcelファイルからMATLAB上へのデータの読み込みを試みました.
n = readmatrix("10000_L9061_R17165.xlsx","Sheet","process","Range","L1:L256");
ところが,「シート名 'process' が存在しないか、またはサポートされていません。シートがサポートされているかどうかをチェックするには、ワークシート インデックスでシートを指定してください。」というエラーメッセージが出てしまい,データを読み込むことができませんでした.
Excelファイル上に'process'のシートが存在しているのは何度も確認しましたし,以前は同様のコードで読み込むことができていたので,なぜ実行できなくなってしまったのかわかりません.
お心当たりのある原因と解決策についてご教授いただけると幸いです.
よろしくお願いいたします.
9 Comments
Dyuman Joshi
on 30 Oct 2023
Could you please attach the excel file you are working with? Use the paperclip button to attach.
駿平
on 30 Oct 2023
Dyuman Joshi
on 30 Oct 2023
I can not seem to open the files. When I click on the excel file (to download it), a new tab opens which says - "An error occurred: unable to locate the file."
Does the file open in your PC? Can you access the contents of the file?
There is a chance that the file might be corrupted.
Atsushi Ueno
on 5 Nov 2023
Edited: Atsushi Ueno
on 5 Nov 2023
ありがちなパターンが「今自分が編集している 10000_L9061_R17165.xlsx とは別の(パスが通っている)場所にも同名の 10000_L9061_R17165.xlsx が存在して、readmatrix 関数は自分の見ているファイルとは異なるファイルを読みに行っている可能性」ですね。
駿平
on 6 Nov 2023
駿平
on 6 Nov 2023
フォルダ階層が深過ぎるという事は無く、その前に文字数制限で引っ掛かります。2バイト文字の文字コード関連の問題もよくありますが、上記はいずれもファイル名のエラーとなるはずで、今回はシート名のエラーです。🤔ワカラン
上記質問は「日付フォーマットが含まれるシート名を除くと問題が解消した」様ですが、本問題には該当しません。
再現するかと思って試してみましたが、このサーバはLinuxなのでWindows固有の問題の場合は再現出来ないです。
一番怪しいのは下記のように長すぎるパス名(260文字)でしょう。
mkdir ./寿限無寿限無五劫のすりきれ海砂利水魚の水行末雲来末風来末食う寝るところに住むところやぶらこうじのぶらこうじパイポパイポパイポのシューリンガンシューリンガンのグーリンダイグーリンダイのポンポコピーのポンポコナーの長久命の長助/左右差/加工時,再締結時/再締結時左右差限界/10000_L17165_R9061
movefile 10000_L9061_R17165.xlsx ./寿限無寿限無五劫のすりきれ海砂利水魚の水行末雲来末風来末食う寝るところに住むところやぶらこうじのぶらこうじパイポパイポパイポのシューリンガンシューリンガンのグーリンダイグーリンダイのポンポコピーのポンポコナーの長久命の長助/左右差/加工時,再締結時/再締結時左右差限界/10000_L17165_R9061
sheets = sheetnames("./寿限無寿限無五劫のすりきれ海砂利水魚の水行末雲来末風来末食う寝るところに住むところやぶらこうじのぶらこうじパイポパイポパイポのシューリンガンシューリンガンのグーリンダイグーリンダイのポンポコピーのポンポコナーの長久命の長助/左右差/加工時,再締結時/再締結時左右差限界/10000_L17165_R9061/10000_L9061_R17165.xlsx")
駿平
on 8 Nov 2023
Answers (1)
MATLAB R2023bでは以下のように問題なく読み取ることができました。
お使いの MATLAB バージョンはどれになりますでしょうか?
filePath = "https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1524651/10000_L9061_R17165.xlsx";
n = readmatrix(filePath, ...
"Sheet", "process", ...
"Range", "L1:L256");
disp(n)
9 Comments
Dyuman Joshi
on 31 Oct 2023
It seems to be working now. And I can download the file as well.
Which makes me think that there was some problem with the file uploaded before.
駿平
on 4 Nov 2023
Dyuman Joshi
on 5 Nov 2023
But there is only 1 sheet in the excel file you have attached.
Have you attached the correct file?
What error occurs when you try read new data?
駿平
on 5 Nov 2023
横やり失礼いたします。差替ファイルでもやはり読み込みに成功しますね。
filePath = "https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1530132/10000_L9061_R17165.xlsx";
n = readmatrix(filePath,Sheet="process",Range="L1:L256");
disp(n);
Dyuman Joshi
on 5 Nov 2023
@駿平, you do not need to apologise for that.
Could you please tell which sheet is giving you the error when you try to read data?
Also, could you copy and paste the error message you get (that means all of the red text) ?
駿平
on 6 Nov 2023
processとliberationの2つのシートから、それぞれL列とJ列(L列が無かったため)を取得してみましたが、やはり問題ないようです。
@Atsushi Ueno さんのコメントの通り、Excelのファイルパスが合ってるかどうか、いま一度ご確認頂けないでしょうか。
filePath = "https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1530132/10000_L9061_R17165.xlsx";
n1 = readmatrix(filePath,Sheet="process",Range="L1:L256");
n2 = readmatrix(filePath,Sheet="liberation",Range="J1:J256");
disp([n1, n2]);
駿平
on 6 Nov 2023
Categories
Find more on スプレッドシート 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!
