'制作报表
Dim doc As New PrintDoc '定义一个报表
Dim tbl As Table = Tables("main_table3")
For ii As Integer = tbl.TopRow To tbl.BottomRow
Dim rw As Row = tbl.Rows(ii)
Dim ra As New prt.RenderArea '定义一个容器
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never '禁止容器因为分页而被垂直分割
ra.SplitHorzBehavior = prt.SplitBehaviorEnum.Never '禁止水平分割
'------------------'成绩表格
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim tp As Table = Tables("考试科目")
For i As Integer = 0 To tp.Rows.Count -1
rt.Rows.Count = 3 '设置总行数
rt.Cols.Count = tp.Rows.Count +1 '设置总列数
rt.Height = 40 '设置表格的高度为80毫米
rt.Cells(0,0).Text= "科目"
rt.Cells(0,i+1).Text= tp.Rows(i)("学科")
rt.Cells(0,i+2).Text= "总分"
rt.Cells(1,0).Text = "分数"
rt.Cells(1,i+1).Text = IIF(rw(tp.Rows(i)("学科")) = 0,"",rw(tp.Rows(i)("学科")))
rt.Cells(1,i+2).Text = rw("总分")
rt.Cells(2,0).Text = "班平均"
rt.Cells(2,i+1).Text =Format(Tables("main_table3").Compute("AVG(" & tp.Rows(i)("学科") & ")","[考试名称] = '" & e.form.controls("考试名称9").Text & "'"),"0.0")
rt.Cells(2,i+2).Text =Format(Tables("main_table3").Compute("AVG(总分)","[考试名称] = '" & e.form.controls("考试名称9").Text & "'"),"0.0")
rt.Rows(0).Style.Font = New Font("微软雅黑", 11, FontStyle.Regular) '设置主标题字体
rt.Rows(1).Style.Font = New Font("微软雅黑", 9, FontStyle.Regular) '设置主标题字体
'设置表格样式
rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.GridLines.All = New Prt.LineDef(0.1, Color.black) '设置网格线颜色大小
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Style.TextAlignHorz = prt.AlignVertEnum.Center '内容水平居中
rt.Style.Spacing.Top = 5
Next
doc.Body.Children.Add(rt) '加入到报表中
'--------------------加入图表
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Chart = e.Form.Controls("Chart1") ' 引用窗口中的图表
Chart.VisualEffect = False
Chart.SeriesList.Clear() '清除图表原来的图系
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = "学生成绩"
Series.Length = tbl.Cols.Count - 3 '设置图系的长度
For c As Integer = 3 To tbl.Cols.count -6
Series.X(c - 1) = c - 1
Series.Y(c - 1) = tbl.Rows(ii)(c)
Chart.AxisX.SetValueLabel(c - 1, tbl.Cols(c).caption) '指定字符表示
Next
'----------------在原图表上添加一个表
Series = Chart.SeriesList.Add() '增加一个图系
Series.Text = "最大值"
此处新增一个图表,y轴绑定为各学科的平均数(上面rt.Cells(2,i+1).Text处的值 ),此处的数据x轴、y轴如何设置???求助求助
Chart.AxisX.AnnoWithLabels = True '启用字符标示
Chart.LegendVisible = True '显示图列
Chart.LegendCompass= CompassEnum.South '图列显示在南方(底端)
Dim rm As New prt.RenderImage
rm.Image = Chart.Image
doc.Body.Children.Add(rm)
Next
Doc.Preview() '预览报表
[此贴子已经被作者于2020/11/19 23:17:18编辑过]