How can I change the font size of non-English text, such as Persian, in a Word document?

조회 수: 1 (최근 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개)

Anushka
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!

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by