How can I change the font size of non-English text, such as Persian, in a Word document?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Les Beckham
2025-3-11
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
回答(1 个)
Anushka
2025-3-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!