How do you write to excel a cell array that contains both strings and numbers?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have to write a relatively large cell array to excel. The text is primarily column headers but the data does have some text intertwined in it. Is there a simple way to do this?
I've done some digging but most everything I've found says use fprintf and specify when data is of a specific type. This data is too large to run something like that.
The text data is in specific columns, if there were a way to identify text data as strings and just tell MATLAB that all other fields are numeric, that's viable.
0 commentaires
Réponses (2)
Guillaume
le 2 Juin 2017
%simple demo
c = {'abcd', 1234; 'foobar', -56}
xlswrite('test.xlsx', c);
I don't know where you've seen most everything that says use fprintf. You cannot write excel files with fprintf which is for writing text files. Excel files are binary (or in newer versions, a complex mess that you'd never write yourself as text).
Fangjun Jiang
le 2 Juin 2017
As long as each cell is a single scalar or a single string, what is wrong with using xlswrite() directly?
TestData={'a',1;2,'b'};
xlswrite('ExcelFile',TestData);
3 commentaires
Bennett
le 10 Jan 2025
Can confirm in 2025 that this does not write any text to the resulting xls file. Hoping someone will see this comment as I am still dealing with this issue. Thanks!
Fangjun Jiang
le 10 Jan 2025
It might be that iOS does not support xlswrite(). In 2025, you might want to check out these new functions writetable(), writematrix(), writecell().
Check the help document of xlswrite() in your MATLAB version to see what it recommends.
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!