function ceshi_Word %利用MATLAB 生成Word 文档 % ceshi_Word % % Copyright 2009 - 2010 xiezhh. % $Revision: 1.0.0.0 $ $Date: 2009/12/14 12:37:00 $ % 设定测试Word 文件名和路径 filespec_user = [pwd '\测试.doc']; % 判断Word 是否已经打开,若已打开,就在打开的Word 中进行操作,否则就打开Word try % 若 Word 服务器已经打开,返回其句柄Word Word = actxGetRunningServer('Word.Application'); catch % 创建一个Microsoft Word 服务器,返回句柄Word Word = actxserver('Word.Application'); end; Word.Visible = 1; % 或 set(Word, 'Visible', 1); % 若测试文件存在,打开该测试文件,否则,新建一个文件,并保存,文件名为测试.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.SaveAs(filespec_user); 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 — 2010 学年 第一学期)'; 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 = Tables; DTI.Borders.OutsideLineStyle = 'wdLineStyleSingle'; DTI.Borders.OutsideLineWidth = 'wdLineWidth150pt'; DTI.Borders.InsideLin...