Matlab生成Word--xdd
摘自《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的更多相关文章
- [转载]Matlab生成Word报告
最近在进行一批来料的检验测试,一个个手动填写报告存图片太慢了,就有了种想要使用Matlab在分析完后数据可以自动生成PDF报告的想法,于是就去网上搜索了相关的资料,发现Matlab中文论坛上有xiez ...
- Aspose.Words简单生成word文档
Aspose.Words简单生成word文档 Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.Documen ...
- php 生成word的三种方式
原文地址 http://www.jb51.net/article/97253.htm 最近工作遇到关于生成word的问题 现在总结一下生成word的三种方法. btw:好像只要是标题带PHP的貌似点击 ...
- 代码批量生成WORD的遇到的问题及解决
好久没搞工具了,最近因为处理大规模公文处理单文档,自己写了个批量处理WORD的程序:在调试过程中,主要遇到两个问题 第一个是WORD的模板 数据很多,但是WORD模板只需要一个,将数据替换WORD里标 ...
- ASP.NET生成WORD文档,服务器部署注意事项
网上转的,留查备用,我服务器装的office2007所以修改的是Microsoft Office word97 - 2003 文档这一个. ASP.NET生成WORD文档服务器部署注意事项 1.Asp ...
- POI生成WORD文档
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- poi生成word文件
一.简介 对于poi来说,poi可以完成对word.excel.ppt的处理.word目前有两种文件格式,一种是doc后缀.另一种是docx后缀的.2007之前的版本都是doc后缀的,这种格式poi使 ...
- Matlab生成M序列的伪随机码
伪随机编码中较常用的是m序列,它是线性反馈移位寄存器序列的一种,其特点是在相同寄存器级数的情况下输出序列周期最长.线性反馈移位寄存器的工作原理是,给定所有寄存器一个初始值,当移位脉冲到来时,将最后一级 ...
- asp.net下调用Matlab生成动态链接库
对于这次论文项目,最后在写一篇关于工程的博客,那就是在asp.net下调用matlab生成的dll动态链接库.至今关于matlab,c/c++(opencv),c#(asp.net)我总共写了4篇配置 ...
随机推荐
- Django中ORM的优化
1. exists( ) 什么时候用 count( ) 和 len( )什么时候合适, 用values( )或values_list( )只取需要的列的数据 iterator()对数据对象生成迭代器, ...
- Java基础(六)判断两个对象相等:equals、hashcode、toString方法
1.equal方法 Object类中的equal方法用于检测一个对象是否等于另外一个对象.在Object类中,这个方法将判断两个对象是否具有相同的引用.如果两个对象具有相同的引用,它们一定是相等的.然 ...
- SpringBoot整合MybatisPlus3.X之Wrapper(五)
官方文档说明: 以下出现的第一个入参boolean condition表示该条件是否加入最后生成的sql中 以下代码块内的多个方法均为从上往下补全个别boolean类型的入参,默认为true 以下出现 ...
- Go语言入门:Hello world
本文是「vangoleo的Go语言学习笔记」系列文章之一. 官网: http://www.vangoleo.com/go/go-hello-world/ 在上一篇文章你好,Go语言中,我们对Go语言的 ...
- NodeJs 实现 WebSocket 即时通讯(版本二)
服务端代码 websocket.js 'use strict' const WebSocket = require('ws'); const connections = new Map(); cons ...
- 不用循环控制、条件控制、三目运算符 实现阶乘n!
long func(int n) { ( n <= 1 && (n=1) ) || ( n*=func(n-1)); return n; } template<int N& ...
- python实现清屏
往常都是用os.system("cls")清屏,但是发现每次执行完这个命令后都会出现一个空白字符 尝试了一下午,网上也没解决的办法 最后: os.system("cls& ...
- 康托展开&逆康托展开学习笔记
啊...好久没写了...可能是最后一篇学习笔记了吧 题目大意:给定序列求其在全排列中的排名&&给定排名求排列. 这就是康托展开&&逆康托展开要干的事了.下面依次介绍 一 ...
- php ffmpeg视频和序列帧转化
php ffmpeg视频和序列帧转化 <pre>$cmd=shell_exec("ffmpeg -i ".__DIR__ . "/shipin1.mp4 -r ...
- 关于Pycharm的注册码
最近安装pycharm,需要注册码,我在网上搜索了许多,这里一一记录下来,供大家参考: 在License server里面尝试输入下面任一地址: http://elporfirio.com:1017 ...