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 Ansichten (letzte 30 Tage)
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 Kommentare
Bob Thompson
Bob Thompson am 16 Jan. 2019
Bearbeitet: Bob Thompson am 16 Jan. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by