Foxtable(狐表)用户栏目专家坐堂 → 专业报表插入表格打印的问题


  共有2530人关注过本帖树形打印复制链接

主题:专业报表插入表格打印的问题

帅哥哟,离线,有人找我吗?
douglas738888
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1172 积分:8772 威望:0 精华:0 注册:2012/4/18 16:28:00
专业报表插入表格打印的问题  发帖心情 Post By:2016/6/12 15:44:00 [只看该作者]

请教老师,我的专业报表中插入了一个TABLE,打印的时候,TABLE中如果一行的内容较多,与另一行不能连接起来;另外,我在TABLE中的列设置了靠左,打印出来居中了,
我上传了代码和实例图片,请老师看看,谢谢!!

实例图片

图片点击可在新窗口打开查看此主题相关图片如下:未标题-1.jpg
图片点击可在新窗口打开查看


Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim cr As New prt.RenderTable() '定义一个表格对象,插入"工作外审副表"
Dim tb As Table = Tables("工作外审副表") '插"工作外审副表"


Dim ColNames As String() = New String(){"卷册名称","图纸图号","提出问题","修订意见"}
Dim ColNames1 As New List(Of String) '插入行号列
For Each cl As Col In tb.Cols '排除隐藏列
    If cl.Visible Then
        ColNames1.Add(cl.Name)
    End If
Next

cr.Width = "Auto" '表格宽度为自动,也就是等于各列设置宽度之和
For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
    cr.Cells(0,c).Text = ColNames(c) '列名作为标题
    cr.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
    cr.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth '列宽等于实际列宽
    If tb.Cols(ColNames(c)).IsNumeric OrElse tb.Cols(ColNames(c)).IsDate Then '如果是数值或日期列
        cr.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.left '数据水平居中
    End If
    For r As Integer = 0 To tb.Rows.Count - 1 '开始填入该列内容
        'cr.Rows(r).Height = 10 '设置插入表行高
        cr.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
    Next
Next

For i As Integer = 0 To tb.Rows.Count  
    'cr.Rows(i).Height = 10 '设置插入表行高
Next
cr.Cols.Insert(0) '在左边插入一列,用于打印行号
cr.Cols(0).Width = 4 '设置插入表行号列的宽度
cr.Cols(1).Width = 10 '设置插入表第一列的宽度
cr.Cols(2).Width = 15 '设置插入表第二列的宽度
For h As Integer = 1 To cr.Rows.Count - 1
    cr.Cells(h,0).text = h '逐行写入行号
Next
cr.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
cr.CellStyle.Spacing.All = 0.5 '单元格内距设为0.5毫米
cr.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
cr.RowGroups(0,1).Header = prt.TableHeaderEnum.All '利用行组,将第一行设为表头
cr.Style.Font = New Font("宋体", 9) '设置字体.


Dim rm As New prt.RenderImage '定义一个图片对象
rm.Image = GetImage("F:\KMATM150412\Images\LOGO.JPG") '设置图片
rm.Width = 45 '宽度等于页面宽度
rm.Height = 6 '高度由图片大小自动决定
'rm.x = 15
'rm.y = 8
rm.Style.ImageAlign.StretchHorz = True '图片水平拉伸
rm.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Left '居中显示
doc.PageHeader = rm '作为页眉使用
'doc.Body.Children.Add(rm) '将图片对象加入报表

Dim rx As New prt.RenderText '定义一个文本对象
Dim CurRow As Row = Tables("项目策划书.工作外审主表").Current
'加入标题
rx.text = "工程设计任务外审记录表"
rx.Style.FontBold = True '字体加粗
rx.Style.Font = New Font("黑体", 18) '设置字体.
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rx.Style.Spacing.Top = 5 '和前面对象的垂直间隔
rx.Style.Spacing.Bottom = 3 '和下面的对象(表格)距离3毫米
doc.Body.Children.Add(rx) '加入到报表中

'指定行数?列数?列宽?行高
rt.Rows.Count = 9 '设置总行数
rt.Cols.Count = 7 '设置总列数
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 15 '设置右边距
Doc.PageSetting.TopMargin = 12 '设置上边距
Doc.PageSetting.BottomMargin = 15 '设置下边距
rt.Width = 180 '设置表格的高度为180毫米
rt.Rows(0).Height = 8 '
rt.Rows(1).Height = 8 '
rt.Rows(2).Height = 8 '
rt.Rows(3).Height = 8 '
rt.Rows(4).Height = 8 '
rt.Rows(5).Height = 8 '
rt.Rows(6).Height = 8 '
rt.Rows(7).Height = 8 '

rt.Cols(0).Width = 12 '设置第1列的宽度
rt.Cols(1).Width = 10 '设置第2列的宽度
rt.Cols(2).Width = 12 '设置第3列的宽度
rt.Cols(3).Width = 12 '设置第4列的宽度
rt.Cols(4).Width = 12 '设置第5列的宽度
rt.Cols(5).Width = 10 '设置第4列的宽度
rt.Cols(6).Width = 20 '设置第4列的宽度

'设置合并单元格
rt.Cells(0,1).SpanCols = 2 '
rt.Cells(0,4).SpanCols = 3 '

rt.Cells(1,1).SpanCols = 2 '
rt.Cells(1,4).SpanCols = 3 '

rt.Cells(2,1).SpanCols = 2 '
rt.Cells(3,0).SpanRows = 4 '

rt.Cells(3,2).SpanCols = 3 '
rt.Cells(4,2).SpanCols = 3 '
rt.Cells(5,2).SpanCols = 3 '
rt.Cells(6,2).SpanCols = 3 '

rt.Cells(7,0).SpanCols = 7 '
rt.Cells(8,0).SpanCols = 7 '

'设置表格样式
rt.CellStyle.Spacing.All = 1 '单元格内容缩进1毫米
rt.Style.GridLines.All = New prt.Linedef '设置网格线
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Rows(7.0).Style.TextAlignVert = prt.AlignVertEnum.Center '
rt.Rows(8.0).Style.TextAlignVert = prt.AlignVertEnum.Top '

'下面很简单,指定每一个单元格的内容
rt.Cells(0,0).Text= "项目编号"
rt.Cells(0,1).Text = CurRow("项目编号")
rt.Cells(0,3).Text= "项目名称"
rt.Cells(0,4).Text = CurRow("项目名称")

rt.Cells(1,0).Text= "会审日期"
rt.Cells(1,1).Text = CurRow("会审日期")
rt.Cells(1,3).Text= "会审主题"
rt.Cells(1,4).Text = CurRow("会审主题")

rt.Cells(2,0).Text= "会审地点"
rt.Cells(2,1).Text = CurRow("会审地点")
rt.Cells(2,3).Text= "会审主持"
rt.Cells(2,4).Text = CurRow("会审主持")
rt.Cells(2,5).Text= "会审记录"
rt.Cells(2,6).Text = CurRow("会审记录")

rt.Cells(3,0).Text= "参会单位"
rt.Cells(3,1).Text= "建设单位"
rt.Cells(3,2).Text = CurRow("建设单位_参加单位")
rt.Cells(3,5).Text= "参会人员"
rt.Cells(3,6).Text = CurRow("建设单位_参加人员")

rt.Cells(4,1).Text= "设计单位"
rt.Cells(4,2).Text = CurRow("设计单位_参加单位")
rt.Cells(4,5).Text= "参会人员"
rt.Cells(4,6).Text = CurRow("设计单位_参加人员")

rt.Cells(5,1).Text= "监理单位"
rt.Cells(5,2).Text = CurRow("监理单位_参加单位")
rt.Cells(5,5).Text= "参会人员"
rt.Cells(5,6).Text = CurRow("监理单位_参加人员")

rt.Cells(6,1).Text= "施工单位"
rt.Cells(6,2).Text = CurRow("施工单位_参加单位")
rt.Cells(6,5).Text= "参会人员"
rt.Cells(6,6).Text = CurRow("施工单位_参加人员")

rt.Cells(7,0).Text= "会审内容记录" '副标题
rt.Cells(8,0).SpanRows = 18
  
rt.Cols(0).Style.TextAlignVert = prt.AlignVertEnum.Center '
rt.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '
rt.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.Center '

rt.Cells(8,0).RenderObject = cr '插入表

rt.RepeatGridLinesVert = True '封口
rt.Cells(7,0).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy '封口
rt.Style.Font = New Font("宋体", 10) '设置字体
rt.Style.LineSpacing = 150 '设置双倍行距

doc.Body.Children.Add(rt) '将表格对象加入到报表中
Doc.Preview() '预览报表
[此贴子已经被作者于2016/6/12 15:45:37编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
狐狸爸爸
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:47449 积分:251065 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2016/6/12 15:53:00 [只看该作者]

最好用能直接运行的例子说话


 回到顶部
帅哥哟,离线,有人找我吗?
douglas738888
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1172 积分:8772 威望:0 精华:0 注册:2012/4/18 16:28:00
  发帖心情 Post By:2016/6/12 16:34:00 [只看该作者]

请老师帮忙看看这个例子
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.foxdb



 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/6/12 17:18:00 [只看该作者]

要合并单元格才够高度

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.foxdb


 回到顶部
帅哥哟,离线,有人找我吗?
douglas738888
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1172 积分:8772 威望:0 精华:0 注册:2012/4/18 16:28:00
  发帖心情 Post By:2016/6/12 17:41:00 [只看该作者]

非常感谢老师的指导!!!!!!

 回到顶部