Write a row with mixed data to xlsx using xlswrite

3 views (last 30 days)
I need to create a spreadsheet with mixed data (one number, one string, one number). Even though I convert a row into a string, the final output is an empty spreadsheet. Here is an example of code summarizing my problem:
id = 1
folder = cellstr('folder')
pos = 3
oneRow = {num2cell(id), folder, num2cell(pos)}
xlswrite('Prova.xlsx', oneRow)
The row "oneRow" does not appear on the output file "Prova.xlsx".
How can I solve this problem?
Thank you!

Answers (2)

Kiran
Kiran on 28 Dec 2015
Edited: Kiran on 28 Dec 2015
Hi,
Input matrix to "xlswrite" cannot have nested cell array that is cells inside cell array. One workaround to your issue could be making array of individual cells like:
xlswrite('Prova.xlsx',[num2cell(id),cellstr('folder'),num2cell(pos)]);
This worked at my end.

Image Analyst
Image Analyst on 28 Dec 2015
You have cells inside of cells. That won't work. You need numbers and strings inside the cells. Try it this way:
id = 1
folder = 'folder'
pos = 3
oneRow = {id, folder, pos}
xlswrite('Prova.xlsx', oneRow)
I tried it and it works. Now, read this.

Community Treasure Hunt

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

Start Hunting!