关于Matlab生成Word程序的修改意见
(2012-05-16 13:10:51)
标签:
杂谈 |
分类: Matlab |
最近在看谢老师的Matlab生成Word的程序,尤其是大飞哥发了感谢贴之后,因为很早之前就在大飞的版块上看见那个帖子了,当时的效果可以说是惊呆了,但是很可惜没有深入研究下去,最后发现功能实在是太强大了,如果掌握这项技术,配合GUI,完全可以做出真正意义上的试验数据处理软件,因为它连结果记录都能直接写出来,都不用你人工去Word里面填写试验数据,虽然大飞哥和谢老师的程序都只是生成一个表格形式,其实稍加改动,完全可以让Matlab自动的去填写刚刚处理后的数据信息,Matlab自带了xlswrite函数,如果不需要改变单元格的属性,一般是够用了的.关键是Word,没有提供可直接读写的函数,需要用Matlab调用Word的服务器,利用VBA的方法在Word里面录制宏,用Matlab遥控Word自动生成数据和表格(这句话form
琛琛),听完琛琛的一席话,第一印象,哇塞,太专业了,也太恐怖了.可是看了谢老师的程序,以及在北京研讨会上PPT的内容后,好像也没想象中的那么难,用谢老师的话来讲,相关的资料太少了,所以谢老师留给我们的这些资料就尤其珍贵了.程序部分真的封装得很好,让人看得一目了然.
感觉步骤就是一步一步教你怎样用Word写你的内容,跟脚本GUI有点类似,我们平时用Word好比是GUIDE,通过选择属性即可,而Matlab写Word和脚本GUI则需要把属性一个一个定义.
http://www.chinavib.com/forum/thread-75703-1-3.html
function ceshi_Word
%利用MATLAB生成Word文档
%
%
%
%
filespec_user = [pwd '\测试.doc'];
try
catch
end;
Word.Visible =
1;
if exist(filespec_user,'file');
else
end
Content = Document.Content;
Selection = Word.Selection;
Paragraphformat = Selection.ParagraphFormat;
Document.PageSetup.TopMargin = 60;
Document.PageSetup.BottomMargin = 45;
Document.PageSetup.LeftMargin = 45;
Document.PageSetup.RightMargin = 45;
Content.Start = 0;
title =
'试
Content.Text = title;
Content.Font.Size = 16 ;
Content.Font.Bold = 4 ;
Content.Paragraphs.Alignment = 'wdAlignParagraphCenter';
Selection.Start = Content.end;
Selection.TypeParagraph;
xueqi = '(
2009
Selection.Text = xueqi;
Selection.Font.Size = 12;
Selection.Font.Bold = 0;
Selection.MoveDown;
paragraphformat.Alignment = 'wdAlignParagraphCenter';
Selection.TypeParagraph;
Selection.TypeParagraph;
Selection.Font.Size = 10.5;
Tables =
Document.Tables.Add(Selection.Range,12,9);
DTI = Document.Tables.Item(1);
DTI.Borders.OutsideLineStyle = 'wdLineStyleSingle';
DTI.Borders.OutsideLineWidth = 'wdLineWidth150pt';
DTI.Borders.InsideLineStyle = 'wdLineStyleSingle';
DTI.Borders.InsideLineWidth = 'wdLineWidth150pt';
DTI.Rows.Alignment = 'wdAlignRowCenter';
DTI.Rows.Item(8).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(8).Borders.Item(3).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(11).Borders.Item(1).LineStyle = 'wdLineStyleNone';
DTI.Rows.Item(11).Borders.Item(3).LineStyle = 'wdLineStyleNone';
column_width = [53.7736,85.1434,53.7736,35.0094,...
row_height = [28.5849,28.5849,28.5849,28.5849,25.4717,25.4717,...
for i = 1:9
end
for i = 1:12
end
for i = 1:12
end
DTI.Cell(1, 4).Merge(DTI.Cell(1, 5));
DTI.Cell(2, 4).Merge(DTI.Cell(2, 5));
DTI.Cell(3, 4).Merge(DTI.Cell(3, 5));
DTI.Cell(4, 4).Merge(DTI.Cell(4, 5));
DTI.Cell(5, 2).Merge(DTI.Cell(5, 5));
DTI.Cell(5, 3).Merge(DTI.Cell(5, 6));
DTI.Cell(6, 2).Merge(DTI.Cell(6, 5));
DTI.Cell(6, 3).Merge(DTI.Cell(6, 6));
DTI.Cell(5, 1).Merge(DTI.Cell(6, 1));
DTI.Cell(7, 1).Merge(DTI.Cell(7, 9));
DTI.Cell(8, 1).Merge(DTI.Cell(8, 9));
DTI.Cell(9, 1).Merge(DTI.Cell(9, 3));
DTI.Cell(9, 2).Merge(DTI.Cell(9, 3));
DTI.Cell(9, 3).Merge(DTI.Cell(9, 4));
DTI.Cell(9, 4).Merge(DTI.Cell(9, 5));
DTI.Cell(10, 1).Merge(DTI.Cell(10, 9));
DTI.Cell(11, 5).Merge(DTI.Cell(11, 9));
DTI.Cell(12, 5).Merge(DTI.Cell(12, 9));
DTI.Cell(11, 1).Merge(DTI.Cell(12, 4));
Selection.Start = Content.end;
Selection.TypeParagraph;
Selection.Text =
'主管院长签字:
Paragraphformat.Alignment = 'wdAlignParagraphRight';
Selection.MoveDown;
DTI.Cell(1,1).Range.Text = '课程名称';
DTI.Cell(1,3).Range.Text = '课程号';
DTI.Cell(1,5).Range.Text = '任课教师学院';
DTI.Cell(1,7).Range.Text = '任课教师';
DTI.Cell(2,1).Range.Text = '授课班级';
DTI.Cell(2,3).Range.Text = '考试日期';
DTI.Cell(2,5).Range.Text = '应考人数';
DTI.Cell(2,7).Range.Text = '实考人数';
DTI.Cell(3,1).Range.Text = '出卷方式';
DTI.Cell(3,3).Range.Text = '阅卷方式';
DTI.Cell(3,5).Range.Text = '选用试卷A/B';
DTI.Cell(3,7).Range.Text = '考试时间';
DTI.Cell(4,1).Range.Text = '考试方式';
DTI.Cell(4,3).Range.Text = '平均分';
DTI.Cell(4,5).Range.Text = '不及格人数';
DTI.Cell(4,7).Range.Text = '及格率';
DTI.Cell(5,1).Range.Text = '成绩分布';
DTI.Cell(5,2).Range.Text
=
'90分以上
DTI.Cell(5,3).Range.Text
=
'80---89分
DTI.Cell(6,2).Range.Text
=
'70--79分
DTI.Cell(6,3).Range.Text
=
'60---69分
DTI.Cell(7,1).Range.Text = ['试卷分析(含是否符合教学大纲、难度、知识覆'...
DTI.Cell(7,1).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(9,2).Range.Text = '签字 :';
DTI.Cell(9,4).Range.Text
= '年
DTI.Cell(10,1).Range.Text = '教研室审阅意见:';
DTI.Cell(10,1).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(10,1).VerticalAlignment = 'wdCellAlignVerticalTop';
DTI.Cell(11,2).Range.Text =
'教研室主任(签字):
DTI.Cell(11,2).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(8,1).Range.ParagraphFormat.Alignment = 'wdAlignParagraphLeft';
DTI.Cell(8,1).VerticalAlignment = 'wdCellAlignVerticalTop';
DTI.Cell(9,2).Borders.Item(2).LineStyle = 'wdLineStyleNone';
DTI.Cell(9,2).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(9,3).Borders.Item(4).LineStyle = 'wdLineStyleNone';
DTI.Cell(11,1).Borders.Item(4).LineStyle = 'wdLineStyleNone';
Shape = Document.Shapes;
ShapeCount = Shape.Count;
if ShapeCount ~= 0;
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]);
data = normrnd(0,1,1000,1);
hist(data);
grid on;
xlabel('考试成绩');
ylabel('人数');
hgexport(zft, '-clipboard');
DTI.Cell(8,1).Range.Paragraphs.Item(1).Range.PasteSpecial;
Shape.Item(1).WrapFormat.Type = 3;
Shape.Item(1).ZOrder('msoBringInFrontOfText');
delete(zft);
Document.ActiveWindow.ActivePane.View.Type =
'wdPrintView';
Document.Save;
复制代码
可是,再研究的过程中,发现有2个位置需要和谢老师探讨一下.
'set(zft,'visible','on')',这样问题就可以解决了.