0%

MATLAB Report Generator

MATLAB Report Generator提供生成报告的函数以及API,支持输出Pdf、Word、PowerPoint和Html四种格式。

生成报告Demo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
% 生成PDF报告
clc;clear;

% 导入报告基类
import mlreportgen.report.*
import mlreportgen.dom.*

% 创建报告
rpt=Report('Report Demo','docx');

% 生成封面
tp=TitlePage;
tp.Title='Report Demo';
tp.Author='Sppy';
tp.PubDate=char(datetime);
add(rpt,tp);

% 生成目录
add(rpt,TableOfContents);

% 第一章
ch1=Chapter('Chapter 1');
para=Paragraph('可以添加文本、图片、表格、公式等。');
add(ch1,para);

% 1.1节: 文本
sec1_1=Section('文本');
para=Paragraph('添加文本。');
add(sec1_1,para);
para=Paragraph('Add text.');
add(sec1_1,para);
add(ch1,sec1_1);

% 1.2节: 图片
sec1_2=Section('图片');
para=Paragraph('插图如下:');
add(sec1_2,para);
temp=load(which('durer.mat'),'-mat');
fig=figure('Units','Pixels','Position',[200,200,254.5,324]);
image(temp.X);colormap(temp.map);axis('image');
set(gca,'Xtick',[],'Ytick',[],'Units','normal','Position',[0 0 1 1]);
saveas(fig,'test','png');
close(fig);
img=Image('test.png');
add(sec1_2,img);
add(ch1,sec1_2);
close gcf;

% 1.3节: 表格
sec1_3=Section('表格');
para=Paragraph('表格如下:');
add(sec1_3,para);
square=magic(10);
tb=Table(square);
tb.Style={RowSep('solid','black','1px'),ColSep('solid','black','1px'),};
tb.Border='double';
tb.TableEntriesStyle={HAlign('center')};
add(sec1_3,tb);
add(ch1,sec1_3);

% 1.4节: 公式
sec1_4=Section('公式');
para=Paragraph('公式如下:');
add(sec1_4,para);
str=['\cos\frac{2\pi}{17}=-\frac{1}{16}+\frac{1}{16}\sqrt{17}+',...
'\frac{1}{16}\sqrt{34-2\sqrt{17}}+\frac{1}{8}\sqrt{17+3\sqrt{17}-',...
'\sqrt{34-2\sqrt{17}}-2\sqrt{34+2\sqrt{17}}}'];
equ=Equation(str);
add(sec1_4,equ);
equ=Equation('\int^{2\pi}_0x^2\cos{x}\mathrm{d}x=4\pi');
add(sec1_4,equ);
add(ch1,sec1_4);

add(rpt,ch1);

% 第二章
ch2=Chapter('Chapter 2');
para=Paragraph('还可以有第二章。');
add(ch2,para);

add(rpt,ch2);

% 关闭报告
close(rpt);

% 显示报告
rptview(rpt);