-- 作者:sky-18
-- 发布时间:2014/7/17 15:18:00
--
我没有设置行高.因为如果我设置了行高那么每行的高度都一样啊.
但事实是行高会根据备注列变化.如图:
此主题相关图片如下:表内容.jpg
此主题相关图片如下:报表.jpg
第一个图片是项目文件里的表内容,,第二个图片是根据内容生成的报表.
可以看到两行内容的 "原面料"的内容都是"一二三四五六七八九十",,不同的是第一行的备注列很短,而第二行很长.
结果呢,第一行的行高跟备注列变化,导致原面料列显示不完.而第二行因为备注内容很多所以行高又很高.
这是为什么呢.要不我把代码发上来看看.代码有点长,而且写得很乱,怕是看起来有点费力
Dim doc As New PrintDoc \'定义一个报表 doc.PageSetting.PaperKind = 9 \'纸张类型改为A4 Doc.PageSetting.LeftMargin = 10 \'设置左边距 Doc.PageSetting.RightMargin = 10 \'设置右边距 Doc.PageSetting.TopMargin = 10 \'设置上边距 Doc.PageSetting.BottomMargin = 5 \'设置下边距 Dim rt1 As New prt.RenderText \'定义一个文本对象 Dim beiz As New prt.RenderText \'定义一个文本对象 Dim yaoq As New prt.RenderText \'定义一个文本对象 Dim yj As New prt.RenderText \'定义一个文本对象 Dim gdzj As New prt.RenderText \'定义一个文本对象 Dim rtb As New prt.RenderTable() \'定义一个表格对象 Dim hs As Integer = Tables("订单.订单数据").rows.Count rt1.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rt1.Style.Spacing.Bottom = 1 \'设置下间隔为3毫米 rt1.Text = "亚泰B227" rt1.Style.Font = New Font("宋体", 28, FontStyle.Bold) \'设置字体 rtb.Style.GridLines.All = New prt.Linedef \'设置网格线 rtb.Rows.Count = hs + 7 rtb.Cols.count = 8 rtb.Width = "auto" rtb.Cols(0).Width = 20 rtb.Cols(1).Width = 30 rtb.Cols(2).Width = 15 rtb.Cols(3).Width = 19 rtb.Cols(4).Width = 8 rtb.Cols(5).Width = 8 rtb.Cols(6).Width = 10 rtb.Cols(7).width = 80 rtb.RowGroups(0,1).Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 rtb.RowGroups(0,1).Style.Font = New Font("宋体", 16, FontStyle.Bold) rtb.RowGroups(1,1).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rtb.RowGroups(1,1).Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 rtb.RowGroups(1,1).Style.Font = New Font("宋体", 16, FontStyle.Bold) rtb.RowGroups(2,hs).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rtb.RowGroups(2,hs).Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 rtb.RowGroups(2,hs).Style.Font = New Font("宋体", vars("ziti"), FontStyle.Bold) rtb.cells(0,0).Text = "单号:" & Tables("订单").Current("单号") rtb.cells(0,2).Text = "订货日期:" & Tables("订单").Current("订货日期") Dim qx As New TimeSpan(Tables("订单").current("期限"),0,0,0) Dim dhrq As Date = Tables("订单").current("订货日期") rtb.cells(0,7).text = "到货日期:" & dhrq + qx rtb.cells(1,0).Text = "货号" rtb.cells(1,1).Text = "原面料" rtb.cells(1,2).Text = "原色" rtb.cells(1,3).Text = "现货号" rtb.cells(1,4).Text = "件数" rtb.cells(1,5).Text = "规格" rtb.cells(1,6).Text = "单价" rtb.cells(1,7).Text = "备注" For i As Integer = 2 To hs + 1 Dim rx2 As New prt.RenderText \'定义一个文本对象 rx2 = New prt.RenderText \'创建一个新的文本对象 rx2.text = Tables("订单.订单数据").rows(i-2)("原货号") \'设置文本对象的内容 rx2.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,0).RenderObject = rx2 \'放置在单元格中 Dim rx21 As New prt.RenderText \'定义一个文本对象 rx21.text = Tables("订单.订单数据").rows(i-2)("原面料") \'设置文本对象的内容 rx21.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,1).RenderObject = rx21 \'放置在单元格中 Dim rx22 As New prt.RenderText \'定义一个文本对象 rx22.text = Tables("订单.订单数据").rows(i-2)("原颜色") \'设置文本对象的内容 rx22.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,2).RenderObject = rx22 \'放置在单元格中 Dim rx23 As New prt.RenderText \'定义一个文本对象 rx23.text = Tables("订单.订单数据").rows(i-2)("现货号") \'设置文本对象的内容 rx23.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,3).RenderObject = rx23 \'放置在单元格中 Dim rx24 As New prt.RenderText \'定义一个文本对象 rx24.text = Tables("订单.订单数据").rows(i-2)("件数") \'设置文本对象的内容 rx24.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,4).RenderObject = rx24 \'放置在单元格中 Dim rx25 As New prt.RenderText \'定义一个文本对象 rx25.text = Tables("订单.订单数据").rows(i-2)("规格") \'设置文本对象的内容 rx25.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,5).RenderObject = rx25 \'放置在单元格中 Dim rx26 As New prt.RenderText \'定义一个文本对象 rx26.text = Tables("订单.订单数据").rows(i-2)("厂价") \'设置文本对象的内容 rx26.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,6).RenderObject = rx26 \'放置在单元格中 Dim rx27 As New prt.RenderText \'定义一个文本对象 rx27.text = Tables("订单.订单数据").rows(i-2)("备注") \'设置文本对象的内容 rx27.Style.Spacing.All = 1 \'内容和网格线的距离为1 rtb.Cells(i,7).RenderObject = rx27 \'放置在单元格中 rtb.cells(i,7).Style.TextAlignHorz = prt.AlignHorzEnum.left \'水平靠左 Next beiz = New prt.RenderText \'创建一个新的文本对象 beiz.text = "备注: " \'设置文本对象的内容 beiz.Style.Spacing.All = 1 \'内容和网格线的距离为1 beiz.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.Cells(hs+2,0).RenderObject = beiz \'放置在单元格中 rtb.cells(hs+2,0).Style.TextAlignHorz = prt.AlignHorzEnum.right \'水平靠右
beiz = New prt.RenderText \'创建一个新的文本对象 beiz.text = Tables("订单").Current("生产备注") \'设置文本对象的内容 beiz.Style.Spacing.All = 1 \'内容和网格线的距离为1 beiz.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.Cells(hs+2,1).RenderObject = beiz \'放置在单元格中 rtb.cells(hs+2,1).Style.TextAlignHorz = prt.AlignHorzEnum.left \'水平靠右 rtb.cells(hs+2,1).Style.Borders.left = new prt.linedef(0,Color.red)
rtb.cells(hs+2,1).spancols = 7 rtb.cells(hs+2,0).Style.TextAlignHorz = prt.AlignHorzEnum.left \'水平靠左 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = "大货要求" yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 25, FontStyle.Bold) \'设置字体 rtb.Cells(hs+3,0).RenderObject = yaoq \'放置在单元格中 rtb.cells(hs+3,0).SpanRows = 3 rtb.cells(hs+3,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rtb.cells(hs+3,0).Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = "1.商标" yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.Cells(hs+3,1).RenderObject = yaoq \'放置在单元格中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = "2.配码" yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.Cells(hs+4,1).RenderObject = yaoq \'放置在单元格中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = "3.里皮" yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.Cells(hs+5,1).RenderObject = yaoq \'放置在单元格中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = " " & Tables("订单").Current("商标") yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.cells(hs+3,2).SpanCols = 6 rtb.Cells(hs+3,2).RenderObject = yaoq \'放置在单元格中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = " " & Tables("订单").Current("配码") yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.cells(hs+4,2).SpanCols = 6 rtb.Cells(hs+4,2).RenderObject = yaoq \'放置在单元格中 yaoq = New prt.RenderText \'创建一个新的文本对象 yaoq.Text = " " & Tables("订单").Current("里皮") yaoq.Style.Spacing.All = 1 \'内容和网格线的距离为1 yaoq.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 rtb.cells(hs+5,2).SpanCols = 6 rtb.Cells(hs+5,2).RenderObject = yaoq \'放置在单元格中 gdzj = New prt.RenderText \'创建一个新的文本对象 gdzj.Text = "本单件数总计:" & Tables("订单").Current("该单件数") gdzj.Style.Spacing.All = 1 \'内容和网格线的距离为1 gdzj.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 gdzj.style.TextColor = Color.red rtb.cells(hs+6,0).SpanCols = 6 rtb.Cells(hs+6,0).RenderObject = gdzj \'放置在单元格中 rtb.cells(hs+6,0).Style.Borders.left = new prt.linedef(0,Color.red) rtb.cells(hs+6,0).Style.Borders.Bottom = new prt.linedef(0,Color.red) gdzj = New prt.RenderText \'创建一个新的文本对象 gdzj.Text = "本单金额总计:" & Tables("订单.订单数据").Compute("sum(厂金额)") gdzj.Style.Spacing.All = 1 \'内容和网格线的距离为1 gdzj.Style.Font = New Font("宋体", 16, FontStyle.Bold) \'设置字体 gdzj.style.TextColor = Color.red rtb.cells(hs+6,6).SpanCols = 2 rtb.Cells(hs+6,6).RenderObject = gdzj \'放置在单元格中 rtb.cells(hs+6,6).Style.Borders.left = new prt.linedef(0,Color.red) rtb.cells(hs+6,6).Style.Borders.Bottom = new prt.linedef(0,Color.red) rtb.cells(hs+6,6).Style.Borders.Right = new prt.linedef(0,Color.red) Dim zd As New Dictionary(Of Integer,Integer) Dim jh1 As New List(Of Integer) Dim jh2 As New List(Of Integer) zd.Add(0,1) Dim wz As Integer = 0 Dim sl As Integer = 1 For k As Integer = 3 To hs + 1 If Tables("订单.订单数据").rows(k-2)("原货号") = Tables("订单.订单数据").rows(k-3)("原货号") Then zd.Remove(wz) sl = sl + 1 zd.Add(wz,sl) Else If Tables("订单.订单数据").rows(k-2)("原货号") <> Tables("订单.订单数据").rows(k-3)("原货号") Then sl = 1 wz = k - 2 zd.Add(wz,sl) End If Next Dim jian As New List(of Integer) jian.AddRange(zd.Keys) For x As Integer = 0 To jian.Count-1 rtb.cells(jian(x)+2,0).Spanrows = zd(jian(x)) rtb.cells(jian(x)+2,1).Spanrows = zd(jian(x)) rtb.cells(jian(x)+2,2).Spanrows = zd(jian(x)) rtb.Cells(jian(x)+2,0).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy rtb.Cells(jian(x)+2,1).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy rtb.Cells(jian(x)+2,2).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy Next yj = New prt.RenderText \'设置文本对象的内容 yj.Text = "第[PageNo]页,共[PageCount]页 " & Tables("订单").Current("单号") \'设置文本内容 yj.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'居中 yj.Style.FontSize = 8 \'字体大小为8磅 Doc.PageFooter = yj \'作为页眉使用 rtb.Cells(0,0).Spancols = 2 rtb.cells(0,2).SpanCols = 5 rtb.RepeatGridLinesVert = True doc.Body.Children.Add(rt1) \'将文本对象加入到报表中 doc.Body.Children.Add(rtb) \'将表格对象加入到报表中 doc.Preview() \'预览
[此贴子已经被作者于2014-7-17 15:20:14编辑过]
|