摘自《MATLAB统计分析与应用:40个案例分析》(谢中华老师著)P452页
function CreatWord
%利用Matlab生成word
filespec_user = [pwd '\测试.docx']; %生成word % 判断Word是否已经打开,若已打开,就在打开的Word中进行操作,否则就打开Word
try
Word = actxGetRunningServer('Word.Application');
catch
Word = actxserver('Word.Application');
end; Word.Visible = ; if exist(filespec_user,'file');
Document = Word.Documents.Open(filespec_user);
% Document = invoke(Word.Documents,'Open',filespec_user);
else
Document = Word.Documents.Add;
try
Document.SaveAs(filespec_user);
catch
Document.SaveAs2(filespec_user);
end
end
Content = Document.Content;
Selection = Word.Selection;
Paragraphformat = Selection.ParagraphFormat;
% 页面设置
Document.PageSetup.TopMargin = ;%上边距为60磅
Document.PageSetup.BottomMargin = ;
Document.PageSetup.LeftMargin = ;
Document.PageSetup.RightMargin = ; % 设定文档内容的起始位置和标题
Content.Start = ; %设文章起始位置为0
headline = '试 卷 分 析';%字符串
Content.Text = headline;
Content.Font.Size = ;%字号
Content.Font.Bold = ;%加粗
Content.Paragraphs.Alignment = 'wdAlignParagraphCenter';%居中对齐
%'wdAlignParagraphLeft' %左对齐
Selection.Start = Content.end;%设置选定区域为文章末尾,即,将光标移到最后
Selection.TypeParagraph;%回车,另起一段
xueqi = '( 2009 — 2010 学年 第一学期)';
Selection.Text = xueqi;
Selection.Font.Size = ;
Selection.Font.Bold = ;
Selection.MoveDown;%光标移至所选区域最后,并取消文字选中状态
Paragraphformat.Alignment = 'wdAlignParagraphCenter';
Selection.TypeParagraph;%回车
Selection.TypeParagraph;
Selection.Font.Size = 10.5; % 在光标所在位置插入一个12行9列的表格
Tables = Document.Tables.Add(Selection.Range,,); DTI = Document.Tables.Item(); % 或DTI = Tables;%获取第一个表格的句柄%全选表格 % 设置表格边框
DTI.Borders.OutsideLineStyle = 'wdLineStyleSingle';%外框线型
DTI.Borders.OutsideLineWidth = 'wdLineWidth150pt';%外框线宽度
DTI.Borders.InsideLineStyle = 'wdLineStyleSingle';%内框线型
DTI.Borders.InsideLineWidth = 'wdLineWidth150pt';%内框线宽度
DTI.Rows.Alignment = 'wdAlignRowCenter';
DTI.Rows.Item().Borders.Item().LineStyle = 'wdLineStyleNone';%设置第八行上框线线型为空
DTI.Rows.Item().Borders.Item().LineStyle = 'wdLineStyleNone';%设置第八行下框线线型为空
DTI.Rows.Item().Borders.Item().LineStyle = 'wdLineStyleNone';%上1,左2,下3,右4,内横5,内竖6,左上斜7,右上斜9
DTI.Rows.Item().Borders.Item().LineStyle = 'wdLineStyleNone'; % 设置表格列宽和行高
column_width = [53.7736,85.1434,53.7736,35.0094,...
35.0094,76.6981,55.1887,52.9245,54.9057]; %9列
row_height = [28.5849,28.5849,28.5849,28.5849,25.4717,25.4717,...
32.8302,312.1698,17.8302,49.2453,14.1509,18.6792]; %12行
for i = : %循环设置列宽
DTI.Columns.Item(i).Width = column_width(i);
end
for i = : %循环设置行高
DTI.Rows.Item(i).Height = row_height(i);
end for i = : % 通过循环设置每个单元格的垂直对齐方式
for j = :
DTI.Cell(i,j).VerticalAlignment = 'wdCellAlignVerticalCenter';
end
end % 合并单元格
DTI.Cell(, ).Merge(DTI.Cell(, ));%%从 第1行第四列 到 第一行第五列 合并为一个单元格
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, ));
DTI.Cell(, ).Merge(DTI.Cell(, )); Selection.Start = Content.end;
Selection.TypeParagraph;
Selection.Text = '主管院长签字: 年 月 日'; %直接赋值,取消了标识符
Paragraphformat.Alignment = 'wdAlignParagraphRight'; %右对齐
Selection.MoveDown; %光标移至所选区域最后,并取消文字选中状态 % 写入表格内容
DTI.Cell(,).Range.Text = '课程名称'; %%注意,单元格合并后,单元格的编号会变化,要找准位置
DTI.Cell(,).Range.Text = '课程号';
DTI.Cell(,).Range.Text = '任课教师学院';
DTI.Cell(,).Range.Text = '任课教师';
DTI.Cell(,).Range.Text = '授课班级';
DTI.Cell(,).Range.Text = '考试日期';
DTI.Cell(,).Range.Text = '应考人数';
DTI.Cell(,).Range.Text = '实考人数';
DTI.Cell(,).Range.Text = '出卷方式';
DTI.Cell(,).Range.Text = '阅卷方式';
DTI.Cell(,).Range.Text = '选用试卷A/B';
DTI.Cell(,).Range.Text = '考试时间';
DTI.Cell(,).Range.Text = '考试方式';
DTI.Cell(,).Range.Text = '平均分';
DTI.Cell(,).Range.Text = '不及格人数';
DTI.Cell(,).Range.Text = '及格率';
DTI.Cell(,).Range.Text = '成绩分布';
DTI.Cell(,).Range.Text = '90分以上 人占 %';
DTI.Cell(,).Range.Text = '80---89分 人占 %';
DTI.Cell(,).Range.Text = '70--79分 人占 %';
DTI.Cell(,).Range.Text = '60---69分 人占 %';
DTI.Cell(,).Range.Text = ['试卷分析(含是否符合教学大纲、难度、知识覆'...
'盖面、班级分数分布分析、学生答题存在的共性问题与知识掌握情况、教学中'...
'存在的问题及改进措施等内容)']; %中括号,是因为一行写不完字符串
DTI.Cell(,).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(,).Range.Text = '签字 :';
DTI.Cell(,).Range.Text = '年 月 日';
DTI.Cell(,).Range.Text = '教研室审阅意见:';
DTI.Cell(,).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(,).VerticalAlignment = 'wdCellAlignVerticalTop'; %靠上
DTI.Cell(,).Range.Text = '教研室主任(签字): 年 月 日';
DTI.Cell(,).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(,).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft'; DTI.Cell(,).VerticalAlignment = 'wdCellAlignVerticalTop'; %靠上
DTI.Cell(,).Borders.Item().LineStyle = 'wdLineStyleNone'; %取消(,)的左边框
DTI.Cell(,).Borders.Item().LineStyle = 'wdLineStyleNone';
DTI.Cell(,).Borders.Item().LineStyle = 'wdLineStyleNone';
DTI.Cell(,).Borders.Item().LineStyle = 'wdLineStyleNone'; % 如果当前工作文档中有图形存在,通过循环将图形全部删除
Shape = Document.Shapes;
ShapeCount = Shape.Count;
if ShapeCount ~= ;
for i = :ShapeCount;
Shape.Item().Delete;
end;
end; % 产生正态分布随机数,画直方图,并设置图形属性
zft = figure('units','normalized','position',...
[0.280469 0.553385 0.428906 0.251302],'visible','off');
set(gca,'position',[0.1 0.2 0.85 0.75]);
rng('default');
data = normrnd(,,,);
hist(data);
grid on;
xlabel('考试成绩');
ylabel('人数');
% options.Fotmat='jpeg';
% hgexport(gcf,'D:\xie.jpeg',options); % 将图形复制到粘贴板
hgexport(zft, '-clipboard');
delete(zft); % Selection.Range.PasteSpecial;
DTI.Cell(,).Range.Paragraphs.Item().Range.PasteSpecial;
% Shape.Item().WrapFormat.Type =; %%外部图片才可以设置文字环绕方式,内部的不行
% Shape.Item().ZOrder('msoBringInFrontOfText'); Document.ActiveWindow.ActivePane.View.Type = 'wdPrintView';
Document.Save;

在Word里面的表格某一单元格粘贴图片

 DTI.Cell(,).Range.Select;    %选中这个单元格,DTI是表格号
DTI.Cell(,).Range.Text = ' ';%将光标移到这里
filename = ['D:\收款.jpg']; %选择图片 Selection.InlineShapes.AddPicture(filename) %粘贴进去

Matlab生成Word--xdd的更多相关文章

  1. [转载]Matlab生成Word报告

    最近在进行一批来料的检验测试,一个个手动填写报告存图片太慢了,就有了种想要使用Matlab在分析完后数据可以自动生成PDF报告的想法,于是就去网上搜索了相关的资料,发现Matlab中文论坛上有xiez ...

  2. Aspose.Words简单生成word文档

    Aspose.Words简单生成word文档 Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.Documen ...

  3. php 生成word的三种方式

    原文地址 http://www.jb51.net/article/97253.htm 最近工作遇到关于生成word的问题 现在总结一下生成word的三种方法. btw:好像只要是标题带PHP的貌似点击 ...

  4. 代码批量生成WORD的遇到的问题及解决

    好久没搞工具了,最近因为处理大规模公文处理单文档,自己写了个批量处理WORD的程序:在调试过程中,主要遇到两个问题 第一个是WORD的模板 数据很多,但是WORD模板只需要一个,将数据替换WORD里标 ...

  5. ASP.NET生成WORD文档,服务器部署注意事项

    网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...

  6. POI生成WORD文档

    h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...

  7. poi生成word文件

    一.简介 对于poi来说,poi可以完成对word.excel.ppt的处理.word目前有两种文件格式,一种是doc后缀.另一种是docx后缀的.2007之前的版本都是doc后缀的,这种格式poi使 ...

  8. Matlab生成M序列的伪随机码

    伪随机编码中较常用的是m序列,它是线性反馈移位寄存器序列的一种,其特点是在相同寄存器级数的情况下输出序列周期最长.线性反馈移位寄存器的工作原理是,给定所有寄存器一个初始值,当移位脉冲到来时,将最后一级 ...

  9. asp.net下调用Matlab生成动态链接库

    对于这次论文项目,最后在写一篇关于工程的博客,那就是在asp.net下调用matlab生成的dll动态链接库.至今关于matlab,c/c++(opencv),c#(asp.net)我总共写了4篇配置 ...

随机推荐

  1. 处理echarts用到的数据格式。。。

    1.需求将数据组装: 将typeNumMap中 键为 '1' 的放在数组series 索引为1的data数组中, 将'2'放在索引为2的data数组中,如果 typeNumMap 中没有 对应的 1, ...

  2. 一次flume exec source采集日志到kafka因为单条日志数据非常大同步失败的踩坑带来的思考

    本次遇到的问题描述,日志采集同步时,当单条日志(日志文件中一行日志)超过2M大小,数据无法采集同步到kafka,分析后,共踩到如下几个坑.1.flume采集时,通过shell+EXEC(tail -F ...

  3. Win10 连接CentOS 8 的Docker容器中 SqlServer数据库

    楔子 工作在win10环境下,使用Docker Windows桌面版容器化SqlServer数据库连接使用(主要是想用Docker),但是同时需要Linux系统测试,win10 下VMware 虚拟机 ...

  4. winform 数据库资料导出Excel方法(适用于资料数据较多加载慢,不用呈现至DatagridView)

    Private Sub savefile(ByVal dgv2 As DataTable) Dim app As Object = CreateObject("Excel.Applicati ...

  5. [专题总结]AC自动机

    其实前面的模板也不是1A,我在题库里提前做过,也不必在意罚时,刚开始我在做别的专题 裸模板我就不说了,各个博客讲解的很明白 void insert(string s){ ,len=s.size(); ...

  6. CSPS模拟 69

    $C_n^0=1$ $C_n^0=1$ $C_n^0=1$ 我怎么又双叒叕犯这种错误了啊 (咳檀) T1 WA0,大神题,不会做! T2 就是要找一个最长区间,满足左端点是区间最小值,右端点是区间最大 ...

  7. Box 黑科技 —— 支持手机端反编译 !Box 黑科技 —— 支持手机端反编译 !

    项目地址: Box 文末扫码获取最新安装包 . 前言 有将近一个月没有更新文章了,一方面在啃 AOSP ,消化起来确实比较慢.在阅读的过程中,有时候上来就会陷入源码细节,其实这是没有必要的.刚开始更多 ...

  8. 一种logging封装方法,不会产生重复log

    在调试logging的封装的时候,发现已经调用了logging封装的函数,在被其它函数再调用时,会出现重复的logging.原因是不同的地方创建了不同的handler,所以会重复,可以使用暴力方法解决 ...

  9. nginx目录安全设置

    nginx目录安全设置<pre> location ~ /\. { deny all; }</pre>这样所有隐藏文件都不会以URL方式打开了

  10. html5 textarea 写入换行的方法

    html5 textarea 写入换行的方法<pre> <textarea id="fwe" class="selmiao" cols=&qu ...