How can I change the font size of non-English text, such as Persian, in a Word document?
1 view (last 30 days)
Show older comments
Clc; clear;
wordapp=actxserver(word.application);
wordapp.visible=true;
doc=wordapp.Documents.Add;
paramod=dic.Paragraphs;
paranoid.alignment=1;
for i=1:2 para=paramod.add;
paraman=para.Range;paraman.Text=’سلام’;
paraman.Font.Size=16*i;
paraman.InsertParagraphActer;
end
1 Comment
Les Beckham
on 11 Mar 2025
See my answer in your (nearly) duplicate question here. https://www.mathworks.com/matlabcentral/answers/2175037-how-can-i-change-the-font-size-of-a-non-english-text-in-a-word-document?s_tid=srchtitle
Answers (1)
Anushka
on 27 Mar 2025
There are multiple ways to modify the font size of non-English text in a word document using MATLAB. Following are the two methods you can use:
Method 1: Using the Selection Object
clc; clear;
wordapp = actxserver('Word.Application');
wordapp.Visible = true;
doc = wordapp.Documents.Add;
selection = wordapp.Selection;
persianText = 'سلام';
% First paragraph
selection.TypeText(persianText);
selection.Font.Size = 16;
selection.TypeParagraph;
% Second paragraph with larger font
selection.TypeText(persianText);
selection.Font.Size = 32;
selection.TypeParagraph;
% Clean up (optional)
% doc.Close;
% wordapp.Quit;
% delete(wordapp);
Result:

Method 2: Using the Content Object with Inline Range Formatting
clc; clear;
wordapp = actxserver('Word.Application');
wordapp.Visible = true;
doc = wordapp.Documents.Add;
range1 = doc.Content;
% First Persian text
range1.Text = 'سلام';
range1.Font.Size = 18;
range2 = doc.Content;
range2.InsertParagraphAfter;
% Second Persian text
range2.InsertAfter('سلام');
range2.Font.Size = 30;
% Clean up (optional)
% doc.Close;
% wordapp.Quit;
% delete(wordapp);
Result:

If you need dynamic paragraph insertion and more flexibility -> Use Method 1 (Selection Object).
If you want to format larger selections or entire content efficiently -> Use Method 2 (Content Object).
Hope this helps!
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!