Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
普通会员
注册日期: 2007-08-07
帖子: 64
声望力: 20 ![]() |
![]()
用Matlab编了一段程序,可以生成word文档,文档中带有表格,代码如下:
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'; |
![]() |
![]() |
![]() |
#2 |
普通会员
注册日期: 2007-08-07
帖子: 64
声望力: 20 ![]() |
![]()
生成的文档见附件
|
![]() |
![]() |
![]() |
#3 |
初级会员
注册日期: 2007-06-24
年龄: 42
帖子: 13
声望力: 18 ![]() |
![]()
厉害,谢老师真厉害!!!!11:tongue:
|
![]() |
![]() |
![]() |
#4 |
初级会员
注册日期: 2009-10-31
年龄: 45
帖子: 1
声望力: 0 ![]() |
![]()
太厉害了,顺便问一下,可以在表格中显示图片吗(利用Matlab代码实现)?另外我在Matlab7.1下运行您的这段代码,提示:Attempt to reference field of non-structure array.
|
![]() |
![]() |
![]() |
|
|
![]() |
||||
主题 | 主题作者 | 版面 | 回复 | 最后发表 |
[求助]如何画data(x,y,z) | mitterand | MATLAB论坛 | 0 | 2009-02-02 16:04 |
Cleve’s Corner: Experiments with MATLAB | TechnicalArticles | MATLAB技术文章 | 0 | 2008-12-19 05:51 |
[求助]The input character is not valid in MATLAB statements or expressions. | mumu | MATLAB论坛 | 2 | 2008-11-26 12:58 |
[求助]如何只打开Help | lyzhan | MATLAB论坛 | 0 | 2008-11-23 11:10 |
[求助]各位达人 | beardgh | MATLAB论坛 | 0 | 2008-09-19 16:34 |