word中的matlab的代码如何插入_Matlab往Word里面插入图片范例代码

本文介绍如何在Matlab中将代码插入到Word文档中,通过示例代码展示具体步骤,包括判断Word是否已打开、设置页面布局、插入标题以及调整字体格式。
摘要由CSDN通过智能技术生成

function ceshi_Word

%

设定测试

Word

文件名和路径

filespec_user=[pwd '\

测试

.doc'];

%

判断

Word

是否已经打开,若已打开,就在打开的

Word

中进行操作,

%

否则就打开

Word

try

Word = actxGetRunningServer('Word.Application');

catch

Word = actxserver('Word.Application');

end;

%

设置

Word

属性为可见

set(Word, 'Visible', 1);

%

返回

Word

文件句柄

documents = Word.Documents;

%

若测试文件存在,打开该测试文件,否则,新建一个文件,并保存,文件名为测试

.doc

if exist(filespec_user,'file');

document = invoke(documents,'Open',filespec_user);

else

document = invoke(documents, 'Add');

document.SaveAs(filespec_user);

end

content = document.Content;

selection = Word.Selection;

paragraphformat = selection.ParagraphFormat;

%

页面设置

(

上下左右边距

)

document.PageSetup.TopMargin = 60;

document.PageSetup.BottomMargin = 45;

document.PageSetup.LeftMargin = 45;

document.PageSetup.RightMargin = 45;

%

设定内容起始位置和标题

set(content, 'Start',0);

title='

';

set(content, 'Text',title);

set(paragraphformat, 'Alignment','wdAlignParagraphCenter');

%

居中

% set(paragraphformat, 'Alignment','wdAlignParagraphLeft');

%

居左

% set(paragraphformat, 'Alignment','wdAlignParagraphRight');

%

居右

%

设定标题字体格式

rr=document.Range(0,10);

rr.Font.Size=18;

%

字体大小设置

rr.Font.Bold=4;

%

设置字体加粗

%

设定下面内容的起始位置(将光标放在最后边)

end_of_doc = get(content,'end');

set(selection,'Start',end_of_doc);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值