Write a row with mixed data to xlsx using xlswrite

3 次查看(过去 30 天)
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!

回答(2 个)

Kiran
Kiran 2015-12-28
编辑:Kiran 2015-12-28
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 2015-12-28
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!

Translated by