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);

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐