I'm trying to write a character in Excel using xlswrite but I am unable to do so.
7 views (last 30 days)
Show older comments
the character is
a=' ,OK| ,g'
when i use xlswrite(file,a,sheet,range), the function writes a but with spaces. ie
, O K | , g
Each alphabet is in a different cell.
I want the entire string to come in a single cell. I used a variant xlswrite(file,{a},sheet,range) and the excel file doesn't change.
Please someone help.
Edit: I am executing these through command window:
a=NPV_run{1}
NPV_run is a 72x1 cell whose first element is ' ,OK| ,g'. Note this element is not the same as 'blank,OK|blank,g'. I compared the two strings and the two blank spaces correspond to a mismatch between the two strings.
I then used xlswrite(filename,a,sheet,range) and the result is blank , O K | blank , g each in a different cell. I also tried to use xlswrite(filename,{a},sheet,range), but in this case nothing is written and the cell remains blank.
Hope this was clear enough.
10 Comments
Image Analyst
on 25 Apr 2013
That has nothing to do with it. It's because it's a string, not a cell.
Accepted Answer
Image Analyst
on 25 Apr 2013
Edited: Image Analyst
on 25 Apr 2013
a must be a cell, not a string:
a = {' ,OK| ,OK'};
For example, this works just fine:
ca = {' ,OK| ,OK'};
ca(2) = {'This is column 2 of ca'}; % Assign another cell.
ca{3} = 'This is column 3 of ca'; % Alternate way of specifying a cell.
sheet = 1;
range = 'B4'; % Wherever you want...
xlswrite('deleteme.xls', ca, sheet, range);
9 Comments
Kunal Goyal
on 19 Jul 2017
You can try to convert to cell array of character vectors using C = cellstr(S).
Walter Roberson
on 19 Jul 2017
Unfortunately using cellstr() is not useful in situations where Excel is not available.
With R2013b or later, there is a potential workaround:
t = array2table(ca); %ca can include a mix of numeric and char vectors
writetable(t, 'data.xlsx', 'writevariablenames', false)
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!