フィルターのクリア

Importing Data from excel across multiple sheets and filenames.

228 ビュー (過去 30 日間)
Declan Simons
Declan Simons 2016 年 8 月 25 日
コメント済み: Walter Roberson 2023 年 12 月 9 日
I am attempting to import multiple strings of data from excel spread sheets and was hoping that the same ranges across multiple sheets could be imported with the same command.
Was thinking it would be a for loop but was unsure how to set it up best.
A total of 8 data sets will be imported from 12 sheets. Any help is greatly appreciated or any questions. :)
  3 件のコメント
Guillaume
Guillaume 2016 年 8 月 25 日
Yes, you can pass the same range to each call of xlsread, just as you can pass the same arguments to each call of a function.
It's very unclear what problem you are having.
Declan Simons
Declan Simons 2016 年 8 月 25 日
編集済み: Declan Simons 2016 年 8 月 25 日
I have 12 columns of data that i want associate each with a unique variable. The same process would then need to happen to 12 sheets. So the total output would be 144 sets of data collected from the excel document. Hope that clears up what I'm trying to do.

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 25 日
編集済み: Azzi Abdelmalek 2016 年 8 月 25 日
[~,sheet_name]=xlsfinfo('filename.xlsx')
for k=1:numel(shhet_name)
data{k}=xlsread('filename.xlsx',sheet_name{k})
end
Now all your data are in the variable data. You don't need to associate to each column a variable, because it's a very bad programming practice.
  3 件のコメント
GreenValleyB
GreenValleyB 2022 年 6 月 30 日
is there a way to import data from different worksheets into one variable? Example: variableA contains data from column "B2:B100001" from worksheets X12, X13, X14, X15.
Walter Roberson
Walter Roberson 2023 年 12 月 9 日
@Dyuman Joshi points out,
Answer needs to be updated to mention new robust functions such as writematrix(), writetable() and writecell(). And to notify that xlsread() is not recommended to use.

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

その他の回答 (2 件)

Kristian Opsahl
Kristian Opsahl 2018 年 9 月 12 日
Hi,
This code worked fine to import my data. However it does not import the dates that I have in column A on every sheet. Any workaround/solution to that?
  1 件のコメント
NAGENDRA ACHANTA
NAGENDRA ACHANTA 2019 年 11 月 7 日
Use [~,~,data{k}] instead of data{k}

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


Carlos Riascos
Carlos Riascos 2023 年 2 月 17 日
I would recommend something like this:
[~,sheet_name]=xlsfinfo('filename.xlsx')
for k=sheet_name
[~,~,data.(k{1})]=xlsread('filename.xlsx',k{1});
end
Note: be careful with not having spaces or unallowed symbols in the sheet_name, otherwise use the command replace.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by