Clear Filters
Clear Filters

Importing text from Excel sheets

1 view (last 30 days)
Shawn
Shawn on 21 Mar 2013
I've been working on a script to take an excel workbook, and import text from each sheet. The cell I am importing from in each sheet is the same, so I decided to use a loop; however, the loop's output variable only contains the first designated cell from the last designated sheet and nothing more.
for i=1:3
[ndata,text,alldata]=xlsread('Book1.xls',i,'B7:B7,B15:B15,B22:B22');
end
The 'text' variable, which I am trying to get containing all the cells I need, will end up being a 1x1 cell.
I have tried going through the loop and writing to a text while within the loop, but I am unaware on how to use a "fprintf" command for cell arrays.
In short, what I am trying to do is create a variable of some sort containing the text from multiple cells from multiple sheets, which I can then export to a text document. Any help with absolutely any of this would be incredibly appreciated.

Accepted Answer

ChristianW
ChristianW on 21 Mar 2013
Here's an example on how to use fprintf with cells:
C{1} = sprintf('Hello\n');
c = {'A','B','C';1,2,3};
C{2} = sprintf('%s\t%d\n',c{:});
s = char(C)
fprintf('%s',C{:})

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!