[~,bumen,~] = xlsread('研会通讯录.xlsx','A3:A37');%NUM返回的是excel中的数据,TXT输出的是文本内容,RAW输出的是未处理数据
[~,zhiwu,~] = xlsread('研会通讯录.xlsx','B3:B37');
[~,name,~] = xlsread('研会通讯录.xlsx','C3:C37');
% cellstr(bumen)
% cellstr(zhiwu)
% cellstr(name)
%模板:https://blog.csdn.net/sisyphus_zhou/article/details/40422623/////https://blog.csdn.net/u011511601/article/details/64921268
for i=1:35
a='兹聘';
b=name{i};%得到的是cell数据,需要转化为char数据 %使用{}得到字符矩阵的字符,使用[]得到矩阵类型数据。
% b=b{1};
c='同学为合肥工业大学电气与自动化工程学院第14届研究生会';
d=bumen{i};
% d=d{1};
e=zhiwu{i}; %由于文件命名问题,把这个放到开头
% e=e{1};
f=',聘期一年,自2018年1月至2018年12月。';
filespec_user = (['C:/Users/Administrator/Desktop/聘书/',b,'聘书.docx']);% 设定测试Word文件名和路径
% 判断Word是否已经打开,若已打开,就在打开的Word中进行操作,否则就打开Word
try
%若word服务器已经打开,返回其句柄Word
Word = actxGetRunningServer('Word.Application');
catch
%创建一个Microsoft Word服务器,返回句柄Word
Word = actxserver('Word.Application');
end;
set(Word, 'Visible', 1); %或Word.Visible=1;
% documents = Word.Documents;
% 若测试文件存在,打开该测试文件,否则,新建一个文件,并保存,文件名为测试.doc
if exist(filespec_user,'file');
Document = Word.Documents.Open(filespec_user);
% Document = invoke(Word.Documents,'Open',filespec_user);
else
Document = Word.Documents.Add;
% Document = invoke(Word.Documents, 'Add');
Document.SaveAs2(filespec_user);
end
Content = Document.Content;%返回Document的Content句柄
Selection = Word.Selection;
Paragraphformat = Selection.ParagraphFormat;
% Content=document.Content; %返回Document的Content句柄
set(Content, 'Start',0); %设置文档内容的起始位置
title='聘书';
set(Content, 'Text',title); %输入文字内容
%Content是标题内容
Content.Font.Size=16; %设置字号16
Content.Font.Bold=4; %字体加粗
Content.Paragraphs.Alignment='wdAlignParagraphCenter';%居中
%Selection是正文内容
Selection.Start = Content.end;% 定义开始的位置
Selection.TypeParagraph;
% neirong1='兹聘',name(i),'同学为合肥工业大学电气与自动化工程学院第14届研究生会',bumen(i),zhiwu(i),',聘期一年,自2018年1月至2018年12月。';
neirong2='此聘!';
neirong3=' 共青团合肥工业大学委员会';
neirong4=' 合肥工业大学研究生会';
neirong5=' 二0一八年一月';
Selection.Font.Size = 10.5;%字号
Selection.Text = a;
Selection.Start = Selection.end;%千万千万注意不要忘了更改光标位置,否则这一行的内容会被覆盖
Selection.Text = b;
Selection.Start = Selection.end;
Selection.Text = c;
Selection.Start = Selection.end;
Selection.Text = d;
Selection.Start = Selection.end;
Selection.Text = e;
Selection.Start = Selection.end;
Selection.Text = f;
Selection.Font.Size = 10.5;%字号
Selection.MoveDown;% 下移一行
Selection.Paragraphs.Alignment= 'wdAlignParagraphLeft';
Selection.TypeParagraph;
Selection.Text = neirong2;
% Selection.Text =
Selection.Font.Size = 10.5;%字号
Selection.MoveDown;% 下移一行
Selection.Paragraphs.Alignment = 'wdAlignParagraphLeft';
Selection.TypeParagraph;
Selection.Text = neirong3;
% Selection.Text =
Selection.Font.Size = 10.5;%字号
Selection.MoveDown;% 下移一行% 下移一行
Selection.Paragraphs.Alignment = 'wdAlignParagraphLeft';
Selection.TypeParagraph;
Selection.Text = neirong4;
% Selection.Text =
Selection.Font.Size = 10.5;%字号
Selection.MoveDown;% 下移一行
Selection.Paragraphs.Alignment = 'wdAlignParagraphLeft';
Selection.TypeParagraph;
Selection.Text = neirong5;
% Selection.Text =
Selection.Font.Size = 10.5;%字号
Selection.MoveDown;% 下移一行
Selection.Paragraphs.Alignment = 'wdAlignParagraphLeft';
Selection.TypeParagraph;
Document.Save; % 保存文档
Document.Close; % 关闭文档
end
% Word.Quit; % 退出word服务器
matlab从excel里抓取名字生成聘书
最新推荐文章于 2022-05-02 22:02:13 发布