以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]报表关于表格上下居中的问题?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=157639)

--  作者:2425004926
--  发布时间:2020/10/23 16:04:00
--  [求助]报表关于表格上下居中的问题?
我想要的结果是:表格第一行行高是由方程式算出的一个固定值,第二行根据文字多少自动确定行高,然后整个表上下居中,试了多次,都不成功,蓝色处总有问题,望老师指点一下,谢谢!

 \'定义报表
Dim doc As New PrintDoc \'定义一个报表
doc.PageSetting.PaperKind = 9 \'纸张类型改为A4
doc.PageSetting.Landscape = True \'横向打印
Doc.PageSetting.LeftMargin = 25 \'设置左边距
Doc.PageSetting.RightMargin = 20 \'设置右边距
\'Doc.PageSetting.TopMargin = 20 \'设置上边距
\'Doc.PageSetting.BottomMargin = 20 \'设置下边距

Dim rt As New prt.RenderTable() \'定义一个表格对象
Dim rx As New prt.RenderText \'创建一个文本
Dim rx2 As New prt.RenderText \'创建一个文本
\'表格
rt = New prt.RenderTable() \'定义一个表格对象
rt.Style.GridLines.All = New prt.Linedef(Color.red) \'将表格的颜色设为无色,red,
rt.Width = 100
\'rt.height = 170
rt.rows(0).Height = 50    \'第二行高度
rt.rows(1).Height = "auto"    \'第二行高度

doc.Body.Children.Add(rt) \'将表格对象加入到报表中
\'添加容器
Dim rk As prt.RenderArea
rk = rt.Cells(1,0).Area \'第2行第1列引用单元格的容器
rx = New prt.RenderText \'创建一个文本
rx2 = New prt.RenderText \'再创建一个文本
rk.Stacking = prt.StackingRulesEnum.BlockTopToBottom \'排列方式改为从左到右
\'题名
rx.Text = "增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew方法" \'设置文本对象的内容
rx.Style.Font = New Font("宋体", 15, FontStyle.Bold) \'设置字体如果不设置字体,会出现导出PDF乱码
rx.Style.LineSpacing = 120 \'1.3倍行距
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Left \'水平居中
rx.Style.TextAlignVert = prt.AlignVertEnum.Top \'垂直居下
rx.Style.Spacing.Top = 3 \'距离右边的对象2毫米
rx.Style.Spacing.Bottom = 3 \'距离右边的对象2毫米
\'档案号
rx2.Text =  "增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew方法增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew" \'设置文本对象的内容
rx2.Style.Font = New Font("宋体", 15, FontStyle.Bold) \'设置字体如果不设置字体,会出现导出PDF乱码
rx2.Style.LineSpacing = 120 \'1.3倍行距
rx2.Style.TextAlignHorz = prt.AlignHorzEnum.Left \'水平居中
rx2.Style.TextAlignVert = prt.AlignVertEnum.Top \'垂直居下
rk.Children.Add(rx)
rk.Children.Add(rx2)
MessageBox.Show(rt.height)
\'rt.height = rt.rows(0).Height + rt.rows(1).Height


Dim s As Integer
\'s = CInt((210 - rt.Height)/2)
\'Doc.PageSetting.TopMargin = rt.height \'设置上边距

Doc.Preview() \'预览报表
--  作者:有点蓝
--  发布时间:2020/10/23 16:28:00
--  
只能算个大概

Dim doc As New PrintDoc \'定义一个报表
doc.PageSetting.PaperKind = 9 \'纸张类型改为A4
doc.PageSetting.Landscape = True \'横向打印
Doc.PageSetting.LeftMargin = 25 \'设置左边距
Doc.PageSetting.RightMargin = 20 \'设置右边距
Doc.PageSetting.TopMargin = 0 \'设置上边距
Doc.PageSetting.BottomMargin = 0 \'设置下边距
Dim rt As New prt.RenderTable() \'定义一个表格对象
Dim rx As New prt.RenderText \'创建一个文本
Dim rx2 As New prt.RenderText \'创建一个文本
\'表格
rt = New prt.RenderTable() \'定义一个表格对象
rt.Style.GridLines.All = New prt.Linedef(Color.red) \'将表格的颜色设为无色,red,
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Width = 100
\'rt.height = 170
rt.rows(0).Height = 50    \'第二行高度
\'rt.rows(1).Height = "auto"    \'第二行高度
doc.Body.Children.Add(rt) \'将表格对象加入到报表中
\'添加容器
Dim rk As prt.RenderArea
rk = rt.Cells(1,0).Area \'第2行第1列引用单元格的容器
rx = New prt.RenderText \'创建一个文本
rx2 = New prt.RenderText \'再创建一个文本
rk.Stacking = prt.StackingRulesEnum.BlockTopToBottom \'排列方式改为从左到右
\'题名
rx.Text = "增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew方法" \'设置文本对象的内容
rx.Style.Font = New Font("宋体", 15, FontStyle.Bold) \'设置字体如果不设置字体,会出现导出PDF乱码
rx.Style.LineSpacing = 120 \'1.3倍行距
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Left \'水平居中
rx.Style.TextAlignVert = prt.AlignVertEnum.Top \'垂直居下
rx.Style.Spacing.Top = 3 \'距离右边的对象2毫米
rx.Style.Spacing.Bottom = 3 \'距离右边的对象2毫米
\'档案号
rx2.Text =  "增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew方法增加一行或多行,并返回所增加的第一行,同时将输入焦点移到该行上,等同于Table的AddNew" \'设置文本对象的内容
rx2.Style.Font = New Font("宋体", 15, FontStyle.Bold) \'设置字体如果不设置字体,会出现导出PDF乱码
rx2.Style.LineSpacing = 120 \'1.3倍行距
rx2.Style.TextAlignHorz = prt.AlignHorzEnum.Left \'水平居中
rx2.Style.TextAlignVert = prt.AlignVertEnum.Top \'垂直居下
rk.Children.Add(rx)
rk.Children.Add(rx2)

Dim g As Graphics = basemainform.CreateGraphics
g.PageUnit = GraphicsUnit.Millimeter \'设置计算打印高度时的单位为毫米,和专业报表的单位一致
Dim size As Object
size = g.MeasureString(rx2.Text, rx2.Style.Font, 100)
Dim h As Integer = size.height
msgbox(h)
rt.Y = (210 - (h + 50 ) ) / 2 - 13
msgbox(rt.Y)
\'rt.height = rt.rows(0).Height + rt.rows(1).Height

Dim s As Integer
\'s = CInt((210 - rt.Height)/2)
\'Doc.PageSetting.TopMargin = rt.height \'设置上边距
Doc.Preview() \'预览报表


--  作者:2425004926
--  发布时间:2020/10/23 16:45:00
--  
 非常棒!非常棒!