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!