Change the font color using writecell

8 views (last 30 days)
Amirhossein Moosavi
Amirhossein Moosavi on 2 May 2021
Answered: Image Analyst on 2 May 2021
Hello, I have a cell like below:
A = {'[0.18 0.39 0.62]' } {'[5.21 5.08 5.2]' } {'[2.02 2.03 2]' } {'[0.85 0.03 0.13]' } {'[1 1 1]' }
{'[0 3.68 1.54]' } {'[10.7 11.03 10.8]'} {'[4 4 4]' } {'[0.1 3.9 0.17]' } {'[1 1 1]' };
I would like to export this cell into an excel file using writecell (or anyother function). But I would like to change the color font of these numbers in the excel file such that each number in a string has a specifi color. For example, for the first row and first column of cell A '[0.18 0.39 0.62]':
0.18 => green
0.39 => blue
0.62 => red
Similarly, this pattern should be repeated for the rest of the rows and columns of the cell.
Many thanks

Answers (1)

Image Analyst
Image Analyst on 2 May 2021
Sorry you can't do that yet. In fact even if you use writecell() on an existing workbook that is nicely formatted with cell colors, underlines, fonts, borders, etc., it will blow away all your existing formatting. I informed them of this bug a long time ago and they said it's behaving as designed. I told them their design was terrible and it would force people to remain using xlswrite(), which they deprecated but at least that function does not blow away formatting when writing to an existing workbook.
Please, please, please call them on the phone or send a message to support@mathwork.com and tell them to fix writecell() so it doesn't remove formatting.
Until then your only choice is to continue to use xlswrite(), or use writecell() but then, if using Windows, you'll have to use ActiveX to format it exactly like you want. The xlswrite() option is easier than the ActiveX option but if you want the ActiveX option, see attached Excel class.

Community Treasure Hunt

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

Start Hunting!