Foxtable(狐表)用户栏目专家坐堂 → excel报表列宽


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

主题:excel报表列宽

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


加好友 发短信
等级:四尾狐 帖子:858 积分:6381 威望:0 精华:0 注册:2017/2/13 9:04:00
excel报表列宽  发帖心情 Post By:2021/3/15 10:16:00 [显示全部帖子]

需求:按照内容显示列宽,下面打印报表怎么改?特别是尺码数量不固定,要怎么改?

图片点击可在新窗口打开查看此主题相关图片如下:1212.png
图片点击可在新窗口打开查看

    Dim dtb As New DataTableBuilder("横向销售明细")
    If DataTables.Contains("横向销售明细") = False Then '如果表C没有加载
        DataTables.Load("横向销售明细") '加载表C
    End If
    

    dtb.AddDef("订单号", Gettype(String),65)
    dtb.AddDef("制单号", Gettype(String),65)
    dtb.AddDef("发货日期", Gettype(Date))

    dtb.AddDef("客户", Gettype(String), 60)
    dtb.AddDef("款号", Gettype(String), 60)
    dtb.AddDef("颜色", Gettype(String),60)
    dtb.AddDef("销售单价", Gettype(Decimal),25)
    dtb.AddDef("销售金额", Gettype(Decimal),25)
    'dtb.AddDef("通码", Gettype(Decimal),25)
    dtb.AddDef("发货数量", Gettype(Decimal),25)
    dtb.AddDef("折扣", Gettype(Decimal),25)
    dtb.AddDef("销售发货单号", Gettype(String), 60)

    For Each v As String In DataTables("销售发货明细表").GetValues("尺码","[销售发货单号] = '" & Tables("销售发货_table1").current("销售发货单号") & "'")
        dtb.AddDef(v, Gettype(String))
'"尺码_" & 
    Next
    
    Dim br As DataRow
    br = DataTables("销售发货明细表").Find("[销售发货单号] = '" & Tables("销售发货_Table1").Current("销售发货单号") & "'")

    
    Dim ta As Table = Forms("销售发货").Controls("Table3").Table
    ta.datasource = dtb.BuildDataSource
    Tables("销售发货_table3").DataTable.StopRedraw()
    For Each v As String() In DataTables("销售发货明细表").GetValues("订单号|制单号|发货日期|客户|款号|颜色|销售单价|折扣|销售发货单号","[销售发货单号] = '" & Tables("销售发货_table1").current("销售发货单号") & "'")

        Dim dr1 As Row = ta.AddNew()

        dr1("订单号") = v(0)
        dr1("制单号") = v(1)
        dr1("发货日期") = v(2)
        dr1("客户") = v(3)
        dr1("款号") = v(4)
        dr1("颜色") = v(5)
        dr1("销售单价") = v(6)
        dr1("折扣") = v(7)
        dr1("销售发货单号") = v(8)

        dr1("销售金额") = DataTables("销售发货明细表").Compute("Sum(销售金额)", "客户 = '" & dr1("客户") & "' and 订单号 = '" & dr1("订单号") & "' and 颜色 = '" & dr1("颜色") & "'  and 款号 = '" & dr1("款号") & "'  and 销售发货单号 = '" & dr1("销售发货单号") & "'")
        dr1("发货数量") = DataTables("销售发货明细表").Compute("Sum(发货数量)", "客户 = '" & dr1("客户") & "' and 订单号 = '" & dr1("订单号") & "' and 颜色 = '" & dr1("颜色") & "'  and 款号 = '" & dr1("款号") & "'  and 销售发货单号 = '" & dr1("销售发货单号") & "'")

        For Each dr2 As DataRow In DataTables("销售发货明细表").Select("客户 = '" & v(3) & "' And 订单号 = '" & v(0) & "'and  制单号 = '" & v(1) & "'and  款号 = '" & v(4) & "' and  颜色 = '" & v(5) & "' and  销售发货单号 = '" & v(8) & "' ")
            dr1( dr2("通码")) = dr2("发货数量")           
        Next
        Tables("销售发货_table3").DataTable.ResumeRedraw()
    Next
    

    
    
Dim dt As Table = Tables("销售发货_table3")    

Dim Book As New XLS.Book '定义一个Excel工作簿
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
For c As Integer = 3 To dt.Cols.Count -1 '添加列标题
    Sheet(2, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
    For c As Integer = 3 To dt.Cols.Count -1
        Sheet(r +3, c).Value = dt.rows(r)(c)
    Next
Next
Sheet(1,9).Value = "销售单"
Sheet(1,11).Value = "销售金额"
Sheet(1,12).Value = DataTables("销售发货明细表").Compute("Sum(销售金额)","销售发货单号='" & Tables("销售发货_table1").current("销售发货单号") & "'")
Book.Save("c:\reports\test.xls")
Dim Proc As New Process
Proc.File = "c:\reports\test.xls"
Proc.Start()


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


加好友 发短信
等级:四尾狐 帖子:858 积分:6381 威望:0 精华:0 注册:2017/2/13 9:04:00
  发帖心情 Post By:2021/3/15 10:37:00 [显示全部帖子]

不想搞这么复杂,只要能满足调整不固定列数的列宽就行了,有没有变通的方式,

 回到顶部