Foxtable(狐表)用户栏目专家坐堂 → 专业报表格式化


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

主题:专业报表格式化

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


加好友 发短信
等级:九尾狐 帖子:2466 积分:22761 威望:0 精华:0 注册:2011/3/29 17:14:00
专业报表格式化  发帖心情 Post By:2021/8/7 20:40:00 [只看该作者]

'Dim e  = args(0)
Tables("活动家居产品库").Sort = "产品系列"

Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
'Dim rm As New prt.RenderImage() '定义一个图片对象

''加入标题
'doc.Pagesetting.LandScape = True
rx = New prt.RenderText
rx.Text = "全案定制家居产品清单 "
rx.Style.FontBold = True '字体加粗
rx.Style.FontSize = 16 '大体大小为16磅
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rx.Style.Spacing.Top = 3 '和下面的对象(表格)距离3毫米
rx.Style.Spacing.Bottom = 3 '和下面的对象(表格)距离3毫米
doc.Body.Children.Add(rx) '加入到报表中
doc.PageSetting.PaperKind = 9   '9等于A4纸张
doc.PageSetting.Landscape = False '横向打印
Doc.PageSetting.LeftMargin = 15 '设置左边距
Doc.PageSetting.RightMargin = 5 '设置右边距
Doc.PageSetting.TopMargin = 10 '设置上边距
Doc.PageSetting.BottomMargin = 5 '设置下边距

''设置页眉
Dim rxj As New prt.RenderTable
rxj.Cells(0,0).Image = GetImage("citylogo (2).jpg") '设置图片
''rx.Style.ImageAlign.StretchHorz = False '禁止水平方向扩展图片
''rx.Style.ImageAlign.StretchVert = False '禁止垂直方向扩展图片
rxj.Width = "Auto"  '宽度等于页面宽度
rxj.Height = 5 '高度由图片大小自动决定
rxj.Cells(0,1).Text = "城市之窗家居集团"
rxj.Cells(0,2).Text = "中国驰名商标 / 国家高新企业"
rxj.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left
rxj.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rxj.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right
rxj.Style.Borders.Bottom = New prt.LineDef '设置底边框
rxj.CellStyle.Spacing.Bottom = 0.5 '底端内容缩进0.5毫米
rxj.Style.FontSize = 8 '字体大小为8磅
Doc.PageHeader = rxj '作为页眉使用

'设置页脚
rxj = New prt.RenderTable
rxj.Cells(0,0).Text = Date.Today
rxj.Cells(0,1).Text = "湖南城市之窗全案定制家居美学馆"
rxj.Cells(0,2).Text = "第[PageNo]页,共[PageCount]页"
rxj.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left
rxj.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rxj.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right
rxj.Style.Borders.Top = New prt.LineDef '设置底边框
rxj.CellStyle.Spacing.Bottom = 0.5 '底端内容缩进0.5毫米
rxj.Style.FontSize = 8 '字体大小为8磅
Doc.PageFooter = rxj '作为页眉使用


'Dim CurRow As Row = Tables("活动家居产品库").Current
Dim tbl As Table = Tables("活动家居产品库")
Dim Rows As List(Of DataRow)
Dim Regions As List(Of String) = tbl.DataTable.GetValues("产品系列")

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 tb As Table = Tables("活动家居产品库")
    Dim ColNames As String() = New String(){"展区","展数","商品名称","商品图片","商品编码","规格描述","价格","备注"}
    rt.Style.Font = tb.Font
    rt.Height = "Auto" '设置表格的高度为80毫米
    
    
    
    For c As Integer = 0 To ColNames.Length - 1 '逐列设置和填入内容
        rt.Cells(0,c).Text = ColNames(c) '列名作为标题
        rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center '标题内容水平居中
        If ColNames(c) <> "备注" Then '
            rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth
        End If
        
        For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
            If ColNames(c) <>"商品图片"
                rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
            Else
                Dim name As String = "d:\data\" & filesys.getname(tb.Rows(r)("商品图片"))
                If FileSys.FileExists(name) Then
                Else
                    'msgbox(tb.Rows(r)("商品图片"))
                    Network.DownloadFile(tb.Rows(r)("商品图片"), name)
                End If
                'msgbox(name)
                rt.Cells(r + 1,3).Image = GetImage(name)
                'rt.Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center '居中显示
                '
            End If
            '
        Next
    Next
    
    
    rt.Style.GridLines.All = New prt.Linedef '设置网格线
    rt.Cols(0).Width = 10 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
    rt.Cols(1).Width = 10
    rt.Cols(2).Width = 20
    rt.Cols(3).Width = 30
    rt.Cols(4).Width = 20
    'rt.Cols(5).Width = 30
    rt.CellStyle.Spacing.All = 0.5 '内容距离网格线0.5毫米
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
    'rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
    'rt.Rows(0).Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
    rt.Rows(0).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
    rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '将第一行作为表头..
    doc.Body.Children.Add(rt) '将表格加入到报表
Next
doc.preview()

格式化 数量为 整数 不要小数点  价格列加入 ¥ 符号
图片点击可在新窗口打开查看此主题相关图片如下:企业微信截图_20210807204008.png
图片点击可在新窗口打开查看


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


加好友 发短信
等级:超级版主 帖子:107014 积分:544295 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/8/8 20:23:00 [只看该作者]


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


加好友 发短信
等级:九尾狐 帖子:2466 积分:22761 威望:0 精华:0 注册:2011/3/29 17:14:00
  发帖心情 Post By:2021/8/9 22:47:00 [只看该作者]

这个知道 常规代码会用 就是上面的代码不会提取出 指定列 并指定格式化

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


加好友 发短信
等级:超级版主 帖子:107014 积分:544295 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/8/9 23:09:00 [只看该作者]

For r As Integer = 0 To tb.Rows.Count -1 '开始填入该列内容
            If ColNames(c) <>"商品图片"
if ColNames(c) = “价格”
rt.Cells(r + 1, c).Text = format(tb.Rows(r)(ColNames(c)),"c")
else
                rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c))
endif
            Else

 回到顶部