How can I write the word "Hi" in multiple lines of Word document using different font sizes?
2 ビュー (過去 30 日間)
古いコメントを表示
I wrote This code to disply the word "Hi" in three lines of a Word document with font sizes 16, 32 ,and 48 but it didn't work as expected.
clc
clear
wordApp = actxserver('Word.Application');
wordApp.Visible = true;
doc = wordApp.Documents.Add;
titleText = 'Hi';
Content=doc.Content;
Contentf=Content.font;
for i=1:2
Contentf.bold=true;
Content.paragraphs.alignment=1;
Content.InsertAfter(titleText);
attach=sprintf('%d',i);
Content.InsertAfter(attach);
Contentf.size=16*i;
Content.InsertAfter(char(13));
end
1 件のコメント
採用された回答
Jack
2025 年 3 月 10 日
Try adding a new paragraph for each line and setting the font size on that paragraph's range. For example:
clc;
clear;
wordApp = actxserver('Word.Application');
wordApp.Visible = true;
doc = wordApp.Documents.Add;
for i = 1:3
para = doc.Paragraphs.Add;
para.Range.Text = 'Hi';
para.Range.Font.Size = 16 * i;
para.Range.InsertParagraphAfter;
end
This way, each "Hi" appears on its own line with font sizes 16, 32, and 48 respectively.
Follow me so you can message me anytime with future questions. If this helps, please accept the answer and upvote it as well.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!