doc = New PrintDoc '定义一个报表
doc.PageSetting.PaperKind = 9 '纸张类型
doc.PageSetting.Landscape = True '横向打印
Doc.PageSetting.LeftMargin = 10 '设置左边距
Doc.PageSetting.RightMargin = 10 '设置右边距
Doc.PageSetting.TopMargin = 10 '设置上边距
Doc.PageSetting.BottomMargin = 10 '设置下边距
Dim rtt As new prt.RenderText '定义一个文本对象
'设置页眉
rtt.Text = jg & " T-ETS-621" '设置文本内容
rtt.Style.TextAlignHorz = prt.AlignHorzEnum.Right '靠右对齐
rtt.Style.Padding.Bottom = 0.5 '底端内容缩进0.5毫米
rtt.Style.FontSize = 10 '字体大小为8磅
Doc.PageHeader = rtt '作为页眉使用
rt.RowGroups(0,4).Header = prt.TableHeaderEnum.All '将第一行作为表头.
rt.RepeatGridLinesVert = True
rt.Cols.Count = 14 '设置总列数
rt.Cols(0).Width = 26 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
rt.Cols(1).Width = 24
rt.Cols(2).Width = 24
rt.Cols(3).Width = 25
rt.Cols(4).Width = 10
rt.Cols(5).Width = 15
rt.Cols(6).Width = 20
rt.Cols(7).Width = 16
rt.Cols(8).Width = 15
rt.Cols(9).Width = 15
rt.Cols(10).Width = 19
rt.Cols(11).Width = 18
rt.Cols(12).Width = 15
rt.Cols(13).Width = 10
rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Style.TextAlignHorz = prt.AlignVertEnum.Center '内容平行居中
rt.Style.FontSize = 12
'设置主标题
rt.Cells(0,0).text = Chr(13) & Chr(10) & "现场采样和检测计划"
rt.Cells(0,0).SpanCols = 14 '合并第一行全部单元格,用于显示主标题
rt.Cells(0,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '主标题居中
rt.Cells(0,0).Style.Font = New Font("仿宋", 18, FontStyle.Bold) '设置主标题字体
rt.Rows(0).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第一行的网格线
'设置副标题
rt.Cells(1,0).text = "修订号:003 第[PageNo]页/共[PageCount]页" '通过左边空格数量来调整副标题位置
rt.Cells(1,0).SpanCols = 14 '合并地二行全部单元格,用于显示副标题
rt.Cells(1,0).Style.TextAlignHorz = prt.AlignHorzEnum.right '副标题内容居左
rt.Rows(1).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第二行的网格线
rt.Rows(1).Style.Borders.Bottom = New prt.Linedef '恢复第二行底端的网格线
rt.Cells(2,0).text = "用人单位:" & dr("客户名称") & " 计划采样日期:" & sti & Chr(13) & Chr(10) & "检测类别:" & dr("项目类别") & " 委托序号:" & st1 & " 检测任务编号:" & cmb0 '通过左边空格数量来调整副标题位置
rt.Cells(2,0).SpanCols = 14 '合并地二行全部单元格,用于显示副标题"
rt.Cells(2,0).Style.TextAlignHorz = prt.AlignHorzEnum.left '副标题内容居中
rt.Rows(2).Style.Borders.All = New prt.LineDef("0mm", Color.white) '去掉第二行的网格线
rt.Rows(2).Style.Borders.Bottom = New prt.Linedef '恢复第二行底端的网格线
'rt.Rows(2).Height = 18 '设置第二行的高度,拉开和表格主体的距离.
'设置列标题
rt.Cells(3,0).Text = "车间/工作场所名称"
rt.Cells(3,1).Text = "岗位(工种)"
rt.Cells(3,2).Text = "采样点/对象"
rt.Cells(3,3).Text = "检测项目"
rt.Cells(3,4).Text = "样品数量"
rt.Cells(3,5).Text = "采样方式"
rt.Cells(3,6).Text = "采样时机/时段"
rt.Cells(3,7).Text = "采样流量" & Chr(13) & Chr(10) & "(L/min)"
rt.Cells(3,8).Text = "空气收集器"
rt.Cells(3,9).Text = "采样设备"
rt.Cells(3,10).Text = "样品保存期限和保存条件"
rt.Cells(3,11).Text = "样品编号"
rt.Cells(3,12).Text = "测点编号"
rt.Cells(3,13).Text = "备注"
i = 3
Dim str3 As String
Dim str4 As String
Dim str5 As String
Dim lr As Integer
Dim lr2 As Integer
Dim lr1 As Integer
For Each dr1 In DataTables("样品登记").Select("[客户名称] = '" & st0 & "' and [任务编号] = '" & st1 & "' and [任务序号] = '" & cmb0 & "'" & daaaa,"空白,采样点排序,采样点序号,样品序号,项目名称,采样方式,创建日期")
If dr1("空白") = True Then
str4 = "空白" & dr1("采样点序号")
Else
str4 = Format(dr1("采样点序号"),"000")
End If
If str4 = str3 AndAlso i > 3 AndAlso str5 = dr1("车间名称") & dr1("采样设备") & dr1("空气收集器") & dr1("岗位") & dr1("采样点") & dr1("采样方式") Then
If rt.Cells(i,3).Text.Contains(dr1("项目名称") & ";") Then
If rt.Cells(i,11).Text.EndsWith(dr1("样品序号")) = False Then
rt.Cells(i,4).Text = CInt(rt.Cells(i,4).Text) + CInt(dr1("样品数量"))
If dr1.IsNull("样品序号") Then
rt.Cells(i,11).Text = "/"
Else
rt.Cells(i,11).Text = rt.Cells(i,11).Text & vbcrlf & str4 & "-" & dr1("样品序号")
End If
End If
Else
rt.Cells(i,3).Text = rt.Cells(i,3).Text & ";" & dr1("项目名称") & ";"
rt.Cells(i,3).Text = rt.Cells(i,3).Text.Replace(";;",";")
End If
Else
Dim c As Integer = 0
Dim Merge As Boolean = True
If i = 3 Then
Merge = False
Else
For n As Integer = 0 To c
If rt.Cells(i,n).Text <> rt.Cells(i-1,n).Text Then
Merge = False
Exit For
End If
Next
End If
If Merge Then
rt.Cells(lr,c).SpanRows = rt.Cells(lr,c).SpanRows + 1
Else
' rt.Cells(i + 1, c).Text = rt.Cells(i, c).Text
rt.Cells(i, c).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy '换页后重复单元格
lr = i
End If
c = 1
Merge = True
If i = 3 Then
Merge = False
Else
For n As Integer = 0 To c
If rt.Cells(i,n).Text <> rt.Cells(i-1,n).Text Then
Merge = False
Exit For
End If
Next
End If
If Merge Then
rt.Cells(lr1,c).SpanRows = rt.Cells(lr1,c).SpanRows + 1
Else
' rt.Cells(i + 1, c).Text = rt.Cells(i, c).Text
rt.Cells(i, c).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy '换页后重复单元格
lr1 = i
End If
c = 2
Merge = True
If i = 3 Then
Merge = False
Else
For n As Integer = 0 To c
If rt.Cells(i,n).Text <> rt.Cells(i-1,n).Text Then
Merge = False
Exit For
End If
Next
End If
If Merge Then
rt.Cells(lr2,c).SpanRows = rt.Cells(lr2,c).SpanRows + 1
Else
' rt.Cells(i + 1, c).Text = rt.Cells(i, c).Text
rt.Cells(i, c).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy '换页后重复单元格
lr2 = i
End If
i = i + 1
rt.Cells(i,0).Text = dr1("车间名称")
rt.Cells(i,1).Text = dr1("岗位")
rt.Cells(i,2).Text = dr1("采样点")
rt.Cells(i,3).Text = dr1("项目名称") & ";"
If dr1.IsNull("样品数量") Then
rt.Cells(i,4).Text = ""
Else
rt.Cells(i,4).Text = dr1("样品数量")
End If
If dr1.IsNull("采样方式") Then
rt.Cells(i,5).Text = "/"
Else
rt.Cells(i,5).Text = dr1("采样方式")
End If
If dr1.IsNull("采样时机") Then
rt.Cells(i,6).Text = "/"
Else
rt.Cells(i,6).Text = dr1("采样时机")
End If
If dr1.IsNull("采样流量") Then
rt.Cells(i,7).Text = "/"
Else
rt.Cells(i,7).Text = dr1("采样流量")
End If
If dr1.IsNull("空气收集器") Then
rt.Cells(i,8).Text = "/"
Else
rt.Cells(i,8).Text = dr1("空气收集器")
End If
If dr1.IsNull("采样设备") Then
rt.Cells(i,9).Text = "/"
Else
rt.Cells(i,9).Text = dr1("采样设备")
End If
If dr1.IsNull("样品保存期限和保存条件") Then
rt.Cells(i,10).Text = "/"
Else
rt.Cells(i,10).Text = dr1("样品保存期限和保存条件")
End If
If dr1.IsNull("样品序号") Then
rt.Cells(i,11).Text = "/"
Else
rt.Cells(i,11).Text = str4 & "-" & dr1("样品序号")
End If
If dr1.IsNull("测点编号") Then
rt.Cells(i,12).Text = "/"
Else
rt.Cells(i,12).Text = "▲" & dr1("测点编号") & "#"
End If
rt.Cells(i,13).Text = dr1("备注")
End If
str3 = str4
str5 = dr1("车间名称") & dr1("采样设备") & dr1("空气收集器") & dr1("岗位") & dr1("采样点") & dr1("采样方式")
Next