reading multiple excel files

14 ビュー (過去 30 日間)
Ahmed Khalifa
Ahmed Khalifa 2015 年 6 月 7 日
コメント済み: Image Analyst 2020 年 12 月 14 日
I have afolder with 150 excel file and I want to read all of them one after another and save them in last in another excel sheet
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 7 日
Can you give more details about your data in each Excell file
Ahmed Khalifa
Ahmed Khalifa 2015 年 6 月 7 日
every excel file has one sheet with 4 columns A B C D

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 7 日
folder='E:\fold1'
d=dir(folder)
e={d.name}
f=e(~cellfun(@isempty,regexp(e,'.+(?=\.xlsx)','match')))
for k=1:numel(f)-1
data{k,1}=xlsread(f{k})
end
M=cell2mat(data)
xlswrite('new_file',M)
  1 件のコメント
Ahmed Khalifa
Ahmed Khalifa 2015 年 6 月 7 日
Thanks soooo much alittle nother question ,sorry if i have many excel files with 11 columns for every one and I want to read only column 5,6,7 and write them for all files in only one single file.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 6 月 7 日
Don't use xlsread() for this unless you're prepared to wait a very long time. If you have Windows, you can use ActiveX and get this done in a few seconds. With xlsread(), each time you call it, it has to launch Excel, open your workbook, haul over the data (probably using ActiveX), and finally shut down Excel. With ActiveX, you launch Excel just once, and shut it down just once, so it will be about 150 times faster for 150 workbooks. I attach a demo on how to read and write Excel files with ActiveX. If I have more than 2 files, I never use xlsread or xlswrite - I use ActiveX. If I want more precise control over formatting (decimal places, alignment, coloring, borders, etc.) I use ActiveX, or use a template. It's not hard to learn so don't be afraid - it's just like any other object oriented programming you're used to.
  8 件のコメント
Brooke Beier
Brooke Beier 2020 年 12 月 14 日
I got a similar warning dialog. Your version of xlswrite1.m may have "Excel=evalin('base','Excel');" by default, but the demo needs "Excel = evalin('caller', 'Excel');".
The difference between 'base' and 'caller' makes the demo run for me.
Image Analyst
Image Analyst 2020 年 12 月 14 日
The version I use has caller, not base. I'm attaching it.

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

カテゴリ

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