appdesigner设计,调用word命令,生成word报告。
此处主要通过代码来实现对图片和表格的复制。
同时写入图片和表格时,建议用Selection控制写入图片,用Content控制写入表格
[file, path] = uiputfile('*.docx');%命名文件
if isequal(file,0) || isequal(path,0)
errordlg('未命名文件','错误');%错误提示
return
else
filespec_user = strcat(path,file);% 设Word文件名和路径
end
if exist(filespec_user,'file')
delete(filespec_user);
end
% 判断Word是否已经打开,若已打开,就在打开的Word中进行操作,否则就打开Word
try
% 若Word服务器已经打开,返回其句柄Word
Word = actxGetRunningServer('Word.Application');
catch
% 否则,创建一个Microsoft Word服务器,返回句柄Word
Word = actxserver('Word.Application');
end
Word.Visible = 1; % 写入Word可视化,0则不可见
Document = Word.Documents.Add;
Document.SaveAs2(filespec_user);
Content = Document.Content;
Selection = Word.Selection;
%编辑标题
Content.Start =0;
Content.Text = "差值计算报告";
Content.Paragraphs.Alignment='wdAlignParagraphCenter';%
Content.Font.Name = '宋体' ;
Content.Font.Size=20;
Selection.Start = Content.End;%此处用段落控制图像,content控制出现问题,未解决

最低0.47元/天 解锁文章
8677

被折叠的 条评论
为什么被折叠?



