Problem in writing string data to xlsx file using xlswrite command.

2 views (last 30 days)
I observed an issue in using xlswrite command for saving the string data to xlsx file.
Matlab code:
headers = {'First','Second','Third'};
values = {'2E10','2e3','3F4'};
xlswrite('myExample.xlsx',[headers; values]);
========================
Output in xlsx sheet:
First | Second | Third
------------------------------
2.00E+10 | 2.00E+03 | 3F4
Basically what happened here is that the data is saved as number not as string in second row. But interestingly, the third element is still in string format. So this is a problem with xlswrite command.
Possible solution: If xlswrite command can have the option for changing the property of the data type of xlsx file, then it can be done.
Temporary solution: You can change the property of the xlsx data type manually e.g. as 'text' format and then save the data again in that existing file and it will give the following output in the xlsx sheet.
Output in xlsx sheet:
First| Second | Third
------------------------------
2E10 | 2e3 | 3F4
Please share your thoughts/solutions.
Thank you
Kuldeep

Answers (1)

Image Analyst
Image Analyst on 2 Dec 2015
Kuldeep, you can either
  1. make myExample.xlsx a pre-existing file to use as a template where those cells have been formatted as text in advance before saving the file. Subsequent saves of those numbers will be treated as character strings.
  2. Use ActiveX from MATLAB to pre-format the cells before you poke them in. An ActiveX example is attached. You can do anything you want from ActiveX.

Products

Community Treasure Hunt

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

Start Hunting!