Mithun
Mithun

Reputation: 61

How can I write output of MATLAB to MS Word?

I am reading the input of the MATLAB code from an Excel file using xlsread, after the calculation I am exporting to Word for writing out the report(writetoword.m). In Excel, there is a string which I should read in MATLAB and output in Word.

In Excel file(input.xlsx) it is written 'shoe'.

I read using

[num,txt,raw] = xlsread('input.xlsx');
eng = txt(14,19); % the word 'shoe' in that excel cell

In writetoword.m, I wrote,

test = eng;
WordText(ActXWord,test,Style,[0,1]);

function WordText(actx_word_p,text_p,style_p,enters_p,color_p)
    if(enters_p(1))
        actx_word_p.Selection.TypeParagraph;
    end
    actx_word_p.Selection.Style = style_p;
    if(nargin == 5)
        actx_word_p.Selection.Font.Color=color_p;     
    end

    actx_word_p.Selection.TypeText(text_p);
    actx_word_p.Selection.Font.Color='wdColorAutomatic';
    for k=1:enters_p(2)    
        actx_word_p.Selection.TypeParagraph;
    end
return

It is not printing anything. The error is in the line

actx_word_p.Selection.TypeText(text_p);

now if I write

test = 'eng';
WordText(ActXWord,test,Style,[0,1]);

It will come as eng and not shoe.

How can I fix this problem?

Upvotes: 0

Views: 3266

Answers (1)

Doresoom
Doresoom

Reputation: 7458

You're assigning txt as a cell instead of a string. Use eng = txt{14,19}; instead.

Upvotes: 1

Related Questions