matlab从excel里抓取名字生成聘书

[~,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服务器
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值