How to copy specific column data from all excel sheets and paste it into a new excel sheet by concatenating obtained column data from each sheet below each other??
4 次查看(过去 30 天)
显示 更早的评论
Hi, I have an excel workbook with name 'Bilal.xlsx'. This excel workbook consists of 2 sheets which contains data with 2 columns and 4 rows. Now i need to copy data from sheet 1 such as only from 2nd column from sheet 1 and paste it into new sheet let say 'Sheet A'. Similarly, then i need to copy data from 2nd column of sheet 2 and paste it into the same sheet 'Sheet A' but now the data should be pasted such as:
Sheet1.xlsx =
Name Age
Tom 20
Dick 15
Harry 25
Sheet2.xlsx =
Name Age
Tom 4
Dick 5
Harry 8
After Pasting 'Sheet A' must be look like:
Age
20
15
25
4
5
8
Actually, I have huge excel data and i want to do it for several sheets can anybody tell me how to write a code in MATLAB for such kind of problem. Thanks in advance
9 个评论
Bob Thompson
2019-1-16
编辑:Bob Thompson
2019-1-16
If you are going to use xlsread for multiple sheets then you will need to loop the command to call each sheet. xlsread can only call a single sheet at a time. I would recommend saving the data into a three dimensional array to help organize it for manipulation later.
for i = 1:ns; % ns is number of sheets
data(:,:,i) = xlsread(file,i,range); % Define your range as needed
end
If you need to print the data to multiple sheets as well, then the process is simply reversed.
Note that each time you call xlsread or xlswrite you are opening and closing the excel file. This can be a relatively slow process, so it is generally good practice to call it as few times as possible. For that reason I suggest you combine all of the data you want to print onto each sheet before you print it, that way you only need to print the data to each sheet once.
I have not personally used it, but I have heard that readtable() and writetable() can be used as an alternative to xlsread() and xlswrite(). I don't know that they are any quicker, but is generally used to help organize and present data in a more user friendly manner.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!