-- 作者:狐狸爸爸
-- 发布时间:2013/3/8 10:44:00
--
首先显示复选框:
http://www.foxtable.com/help/topics/1776.htm
打印选中的行:
Dim doc As New PrintDoc \'定义一个新报表 Dim rt As New prt.RenderTable \'定义一个新表格 Dim tb As Table = Tables("订单") rt.Width = "Auto" \'表格宽度为自动,也就是等于各列设置宽度之和 rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded \'表格宽度超出页宽时,可以水平换页 rt.Style.Font = tb.Font Dim rs As List(of Row) = Tables("订单").GetCheckedRows For c As Integer = 0 To tb.Cols.Count -1 \'逐列设置和填入内容 rt.Cells(0,c).Text = tb.Cols(c).Name \'列名作为标题 rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 rt.Cols(c).Width = tb.Cols(c).PrintWidth \'列宽等于实际列宽 If tb.Cols(c).IsNumeric OrElse tb.Cols(c).IsDate Then \'如果是数值或日期列 rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right \'数据水平靠右 End If For r As Integer = 0 To rs.Count -1 \'开始填入该列内容 rt.Cells(r + 1, c).Text = rs(r)(c) Next Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) \'灰色网格线 rt.CellStyle.Spacing.All = 0.5 \'单元格内距设为0.5毫米 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center \'第一行内容水平居中 rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All \'利用行组,将第一行设为表头 doc.Body.Children.Add(rt) \'将表格加入到报表 doc.Preview()
|
-- 作者:狐狸爸爸
-- 发布时间:2013/3/8 15:41:00
--
例如关联表每页5行:
Dim doc As New Printdoc Dim rx As prt.RenderText Dim rt As prt.RenderTable rx = New prt.RenderText rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 5 rx.Text = "类别: " & Tables("类别").Current("类别名称") doc.Body.Children.Add(rx) With Tables("类别.产品") For r As Integer = 0 To .Rows.Count - 1 Step 5 \'关联表每页5行 rt = New prt.RenderTable rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray) rt.CellStyle.Spacing.All = 1 rt.Cols.Count = 4 rt.Cells(0,0).Text = "产品名称" rt.Cells(0,1).Text = "单价" rt.Cells(0,2).Text = "库存量" rt.Cells(0,3).Text = "订购量" rt.Cells(0,4).Text = "再订购量" rt.Cells(0,5).Text = "中止" rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray) rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray) For n As Integer = r To math.min( r + 5,.Rows.count -1) rt.Cells(n - r + 1,0).Text = .rows(n)("产品名称") rt.Cells(n - r + 1,1).Text = .rows(n)("单价") rt.Cells(n - r + 1,2).Text = .rows(n)("库存量") rt.Cells(n - r + 1,3).Text = .rows(n)("订购量") rt.Cells(n - r + 1,4).Text = .rows(n)("再订购量") If .rows(r)("中止") = True Then Dim rm As New prt.RenderImage rm.Image = getImage("Check.Ico") rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center rm.Style.ImageAlign.StretchHorz = False rm.Style.ImageAlign.StretchVert = False rt.Cells(n - r + 1,5).RenderObject = rm End If End If Next End With doc.Body.Children.Add(rt)
rx = New prt.RenderText rx.Style.FontBold = True rx.Style.Spacing.Top = 3 rx.Text = "产品数目: " & Tables("类别.产品").Rows.Count rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right doc.Body.Children.Add(rx)
|
-- 作者:狐狸爸爸
-- 发布时间:2013/3/8 16:36:00
--
我之前提供的只是思路,需要自行调整的。
下面的代码测试通过:
Dim doc As New Printdoc Dim rx As prt.RenderText Dim rt As prt.RenderTable
With Tables("类别.产品") For r As Integer = 0 To .Rows.Count - 1 Step 5 \'关联表每页5行 rx = New prt.RenderText rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 5 rx.Text = "类别: " & Tables("类别").Current("类别名称") doc.Body.Children.Add(rx) rt = New prt.RenderTable rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.Borders.Bottom = New prt.LineDef(0.3,Color.LightGray) rt.CellStyle.Spacing.All = 1 rt.Cols.Count = 4 rt.Cells(0,0).Text = "产品名称" rt.Cells(0,1).Text = "单价" rt.Cells(0,2).Text = "库存量" rt.Cells(0,3).Text = "订购量" rt.Cells(0,4).Text = "再订购量" rt.Cells(0,5).Text = "中止" rt.rows(0).Style.Borders.Top = New prt.LineDef(1,Color.LightGray) rt.rows(0).Style.Borders.Bottom = New prt.LineDef(1,Color.LightGray) For n As Integer = r To math.min( r + 4,.Rows.count -1) rt.Cells(n - r + 1,0).Text = .rows(n)("产品名称") rt.Cells(n - r + 1,1).Text = .rows(n)("单价") rt.Cells(n - r + 1,2).Text = .rows(n)("库存量") rt.Cells(n - r + 1,3).Text = .rows(n)("订购量") rt.Cells(n - r + 1,4).Text = .rows(n)("再订购量") If .rows(r)("中止") = True Then Dim rm As New prt.RenderImage rm.Image = getImage("Check.Ico") rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center rm.Style.ImageAlign.StretchHorz = False rm.Style.ImageAlign.StretchVert = False rt.Cells(n - r + 1,5).RenderObject = rm End If Next doc.Body.Children.Add(rt) If r + 4 < .Rows.Count - 1 Then Dim rp As prt.RenderEmpty \'定一个空对象 rp = new prt.RenderEmpty \'定义一个新的空对象 rp.BreakBefore = prt.BreakEnum.Page \'打印前换页 doc.Body.Children.Add(rp) \'加入到报表中 End If Next End With rx = New prt.RenderText rx.Style.FontBold = True rx.Style.Spacing.Top = 3 rx.Text = "产品数目: " & Tables("类别.产品").Rows.Count rx.Style.TextAlignHorz = prt.AlignHorzEnum.Right doc.Body.Children.Add(rx)
doc.Preview()
|