How can I change the font size of non-English text, such as Persian, in a Word document?
5 ビュー (過去 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!