以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- [求助]晕了!分组打印和打印部分列 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=44004)
|
-- 作者:石四
-- 发布时间:2013/12/20 14:31:00
-- [求助]晕了!分组打印和打印部分列
专业报表事例有说到分组打印,如果希望只打印选定的组,怎么做呢?又或者说如何打印筛选出的行?
设置了一个组合框"日期"筛选出指定日期的行.用下面的代码会打印出所有组的报表:
Dim doc As New PrintDoc Dim rt As Prt.RenderTable Dim rx As prt.RenderText Dim tbl As Table = Tables("记录") \'Dim Date As String = e.Form.Controls("日期").Value Dim Rows As List(Of DataRow) Dim Datas As List(Of String) = tbl.DataTable.GetValues("日期") doc.Pagesetting.LandScape = True For Each Data As String In Datas rx = New prt.RenderText rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 2 rx.Text = "日期: " & Data doc.Body.Children.Add(rx) rt = New prt.RenderTable rt.Style.Font = Tables("记录").Font rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray) rt.Style.Spacing.Bottom = 5 rt.CellStyle.Spacing.All = 1 rt.Style.Font = tbl.Font Rows = tbl.DataTable.Select("[日期] = \'" & Data & "\'") For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name rt.Cols(c).Width = tbl.Cols(c).PrintWidth For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) Next Next rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All doc.Body.Children.Add(rt) Next doc.preview()
[此贴子已经被作者于2013-12-23 14:43:57编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2013/12/20 14:37:00
--
其实很简单,通过Table的Filter属性获取筛选条件:
Dim doc As New PrintDoc Dim rt As Prt.RenderTable Dim rx As prt.RenderText Dim tbl As Table = Tables("记录") \'Dim Date As String = e.Form.Controls("日期").Value Dim Rows As List(Of DataRow) Dim Datas As List(Of String) = tbl.DataTable.GetValues("日期",tbl.Filter) doc.Pagesetting.LandScape = True For Each Data As String In Datas rx = New prt.RenderText rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 2 rx.Text = "日期: " & Data doc.Body.Children.Add(rx) rt = New prt.RenderTable rt.Style.Font = Tables("记录").Font rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray) rt.Style.Spacing.Bottom = 5 rt.CellStyle.Spacing.All = 1 rt.Style.Font = tbl.Font If tbl.Filter = "" Then Rows = tbl.DataTable.Select("[日期] = \'" & Data & "\'") Else Rows = tbl.DataTable.Select("[日期] = \'" & Data & "\' And (" & tbl.Filter & ")") End If For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name rt.Cols(c).Width = tbl.Cols(c).PrintWidth For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) Next Next rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All doc.Body.Children.Add(rt) Next doc.preview()
|
-- 作者:石四
-- 发布时间:2013/12/20 14:46:00
--
一行行对比看,慢慢消化,谢谢!
|
-- 作者:狐狸爸爸
-- 发布时间:2013/12/20 14:47:00
--
我已经用红色标出了不同的地方
|
-- 作者:石四
-- 发布时间:2013/12/23 14:50:00
--
帮助文件事例:分组打印和打印部分列,搞不定一个事例含这两项功能。
Dim doc As New PrintDoc Dim rt As Prt.RenderTable Dim rx As prt.RenderText Dim tbl As Table = Tables("订单") Dim Rows As List(Of DataRow) Dim Regions As List(Of String) = tbl.DataTable.GetValues("日期") doc.Pagesetting.LandScape = True For Each Region As String In Regions rx = New prt.RenderText rx.Style.FontSize = 14 rx.Style.FontBold = True rx.Style.Spacing.Bottom = 2 rx.Text = "日期: " & Region doc.Body.Children.Add(rx) rt = New prt.RenderTable
rt.Style.Font = Tables("订单").Font rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.Style.GridLines.All = New prt.LineDef(0.3,Color.LightGray) rt.Style.Spacing.Bottom = 5 rt.CellStyle.Spacing.All = 1 rt.Style.Font = tbl.Font Rows = tbl.DataTable.Select("[日期] = \'" & Region & "\'") Dim ColNames As String() = New String(){"产品","数量"} For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name rt.Cols(c).Width = tbl.Cols(c).PrintWidth For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) Next Next rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All doc.Body.Children.Add(rt) Next doc.preview()
执行后还是打印出全部列。
|
-- 作者:Bin
-- 发布时间:2013/12/23 15:01:00
--
注意狐爸代码红色部分,套用即可
|
-- 作者:石四
-- 发布时间:2013/12/23 15:05:00
--
以下是引用Bin在2013-12-23 15:01:00的发言: 注意狐爸代码红色部分,套用即可
前面的已解决,现在琢磨分组并只打印部分列。
|
-- 作者:Bin
-- 发布时间:2013/12/23 15:10:00
--
Dim ColNames As String() = New String(){"产品","数量"} For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name rt.Cols(c).Width = tbl.Cols(c).PrintWidth For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) Next Next
这里不要循环所有列,而是循环你想要的列即可.
|
-- 作者:石四
-- 发布时间:2013/12/23 16:21:00
--
以下是引用Bin在2013-12-23 15:10:00的发言:Dim ColNames As String() = New String(){"产品","数量"} For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name rt.Cols(c).Width = tbl.Cols(c).PrintWidth For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) Next Next
这里不要循环所有列,而是循环你想要的列即可.
将For c As Integer = 0 To tbl.Cols.Count - 1 rt.Cells(0,c).Text = tbl.Cols(c).Name 改为: For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容 rt.Cells(0,c).Text = ColNames(c) \'列名作为标题
For r As Integer = 0 To Rows.Count -1 rt.Cells(r + 1, c).Text = rows(r)(tbl.Cols(c).Name) 改为: For r As Integer = 0 To Rows.Count -1 \'开始填入该列内容 rt.Cells(r + 1, c).Text = Rows(r)(ColNames(c))
才得到想要的结果,都是蒙的,不太理解,盼望狐表尽早出可视化的报表。
|
-- 作者:石四
-- 发布时间:2013/12/23 16:36:00
--
在这里做笔记,设定列宽:
Rows = tbl.DataTable.Select("[日期] = \'" & Region & "\'") Dim ColNames As String() = New String(){"产品","数量"} For c As Integer = 0 To ColNames.Length - 1 \'逐列设置和填入内容 rt.Cells(0,c).Text = ColNames(c) \'列名作为标题 rt.Width = "Auto" rt.Cols(c).Width = 20 For r As Integer = 0 To Rows.Count -1 \'开始填入该列内容 rt.Cells(r + 1, c).Text = Rows(r)(ColNames(c)) Next Next
|