| 
[ 本帖最后由 牛小贱 于 2014-3-30 16:52 编辑 ]\n\n用Matlab编了一段程序,可以生成Word文档,文档中含有表格,代码如下:
x
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。您需要 登录 才可以下载或查看,没有账号?我要加入 
  [code]filespec = 'C:\Documents and Settings\Administrator\桌面\xiezh.doc';
 try;
 Word=actxGetRunningServer('Word.Application');
 catch;
 Word = actxserver('Word.Application');
 end;
 
 set(Word, 'Visible', 1);
 documents = Word.Documents;
 if exist(filespec,'file')
 document = invoke(documents,'Open',filespec);
 else
 document = invoke(documents, 'Add');
 document.SaveAs(filespec);
 end
 
 content = document.Content;
 duplicate = content.Duplicate;
 inlineshapes = content.InlineShapes;
 selection = Word.Selection;
 paragraphformat = selection.ParagraphFormat;
 
 %页面设置
 document.PageSetup.TopMargin = 60;
 document.PageSetup.BottomMargin = 45;
 document.PageSetup.LeftMargin = 45;
 document.PageSetup.RightMargin = 45;
 
 set(content, 'Start',0);
 title='试  卷  分  析';
 set(content, 'Text',title);
 set(paragraphformat, 'Alignment','wdAlignParagraphCenter');
 rr=document.Range(0,10);
 rr.Font.Size=16;
 rr.Font.Bold=4;
 
 end_of_doc = get(content,'end');
 set(selection,'Start',end_of_doc);
 
 selection.TypeParagraph;
 set(selection, 'Text','(20     —20     学年 第     学期)');
 selection.Font.Size=12;
 selection.MoveDown;
 set(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,80.9434,53.7736,29.0094,29.0094,76.6981,55.1887,52.9245,54.9057];
 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];
 for i=1:9
 DTI.Columns.Item(i).Width =column_width(i);
 end
 for i=1:12
 DTI.Rows.Item(i).Height =row_height(i);
 end
 for i=1:12
 for j=1:9
 DTI.Cell(i,j).VerticalAlignment='wdCellAlignVerticalCenter';
 end
 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));
 
 end_of_doc = get(content,'end');
 set(selection,'Start',end_of_doc);
 selection.TypeParagraph;
 set(selection, 'Text','主管院长签字:            年    月    日');
 set(paragraphformat, 'Alignment','wdAlignParagraphRight');
 
 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';[/code]生成的文档见附件
 
 |