Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共5 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:狐表-通用打印窗口 打遍项目中所有的表◎

1楼
mr725 发表于:2009/8/27 17:09:00

在任何狐表项目中引用本窗口(看2楼注意事项,附件已重新更正了),或应用本窗口中的控件代码,就可以打印你想要打印的表了~   afterload代码修改重上传!
欢迎大家纠错~   

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:excel报表:狐表-通用打印窗口n.rar


有两个窗口控件:
1、打印按钮代码:

Dim tb As string = Forms("狐表打印").Controls("ComboBox1").text
Dim gs as integer
If tb = "" then
    MessageBox.Show("请选择要打印的表 !", "提示")
else
    Dim s,s1 As String
    For Each cl As Col In Tables( tb).Cols
        If cl.Visible Then
            gs = gs + 1
            If s ="" Then
                s = cl.Name
            Else
                s = s & "," & cl.Name
            End If
        End If
    Next

    Dim dtb As New DataTableBuilder("模板")
    dtb.AddDef("表名", GetType(String), 32)
    dtb.Build()
    tables("模板").visible = true
    With DataTables("模板")
        for ii as integer = 1 to gs
            .DataCols.Add("列" & ii, GetType(String), 32)
        next
    End With
    Tables("模板").AddNew(8)
    dim zs as integer = fix((gs+1)/2)
    Tables("模板").rows(1)(zs) = tables(tb).name & "表"     ‘没发现这条代码和下面重复了,应用时请删除

    for i as integer = 0 to Tables("模板").cols.count-1
        if i <= gs-1
            Tables("模板").rows(1)(i+1) = ""                  '这条也多余了,原用固定表时才有效
            Tables("模板").rows(2)(i+1) = s.split(",")(i)
            Tables("模板").rows(3)(i+1) = "[" & s.split(",")(i) & "]"
        else          '*********这段代码多余了,原来是用于固定表的 有了上面自动增加列数后就没用了  Start 
            if i>gs-1 andalso i+1 < Tables("模板").cols.count-1
                Tables("模板").rows(1)(i+1) = ""
                Tables("模板").rows(2)(i+1) = ""
                Tables("模板").rows(3)(i+1) = ""   '*********这段代码多余了,原来是用于固定表的 End

            end if
        end if
    next
   
    if tables(tb).name.contains("表") then
        Tables("模板").rows(1)(zs) = tables(tb).name
    else
        Tables("模板").rows(1)(zs) = tables(tb).name & "表"
    end if
    Tables("模板").rows(3)(0) = "<" & tb & ">"
    DataTables("模板").Save(True)
   
    Tables("模板").select(0,0,Tables("模板").count-1,Tables("模板").cols.count-1)
    If FileSys.DirectoryExists("D:\FoxFolder1\Attachments") Then
    Else
        FileSys.CreateDirectory("D:\FoxFolder1\Attachments")
    End If
    If FileSys.DirectoryExists("D:\FoxFolder1\reports") Then 
    Else
        FileSys.CreateDirectory("D:\FoxFolder1\reports")
    End If
    dim tb1 as string = "D:\FoxFolder1\Attachments\" & tb & ".xls"
    dim tb2 as string =  "D:\FoxFolder1\reports-:special:1:- & tb & ".xls"   'reports后\ " & tb & ".xls 贴不上
    If FileSys.FileExists(tb1) Then
        FileSys.DeleteFile(tb1,2,2)
    end if   
    Tables("模板").SaveExcel(tb1,tb,true)
    Tables(tb).select(0,0,Tables(tb).count-1,Tables(tb).cols.count-1)  
    Dim Book1 As New XLS.Book(tb1)
    Dim Sheet As XLS.Sheet = Book1.Sheets(0)
    Sheet.Rows.RemoveAt(0)
    Sheet.Rows(1).Height = 40

    Dim Style As XLS.Style = Book1.NewStyle
    Style.FontBold = True
    Sheet(1,zs).Style = Style
   
    Dim Style1 As XLS.Style = Book1.NewStyle()
    Style1.BorderTop = XLS.LineStyleEnum.Thin
    Style1.BorderBottom = XLS.LineStyleEnum.Thin
    Style1.BorderLeft = XLS.LineStyleEnum.Thin
    Style1.BorderRight = XLS.LineStyleEnum.Thin
    For r As Integer = 2 to 3
        For c As Integer =0 To gs
            Sheet(r,c).Style = Style1
        Next
    Next
    Book1.Build()
    Book1.Save(tb2) 
    Dim Proc As New Process
    Proc.File = tb2
    Proc.Start()
End If
DataTables.Delete("模板")


2、窗口Afterload 代码

dim bm as string
For Each dt As DataTable In DataTables
    If bm ="" Then
        bm = dt.Name
    Else
        bm = bm & "|" & dt.Name
    End If
Next
Dim cmb As WinForm.ComboBox = e.form.Controls("ComboBox1")
cmb.ComboList = bm



[此贴子已经被作者于2009-8-27 19:23:07编辑过]
2楼
狐狸爸爸 发表于:2009/8/27 17:14:00

这一行:

Dim tb As string = Forms("狐表打印").Controls("ComboBox1").text

应该改为:

Dim tb As string = e.form.Controls("ComboBox1").text

否则应用窗口模板后,除非窗口名称也改为狐表打印,否则一定出错。

3楼
mr725 发表于:2009/8/27 17:16:00
以下是引用狐狸爸爸在2009-8-27 17:14:00的发言:

这一行:
Dim tb As string = Forms("狐表打印").Controls("ComboBox1").text
应该改为:
Dim tb As string = e.form.Controls("ComboBox1").text
否则应用窗口模板后,除非窗口名称也改为狐表打印,否则一定出错。

哦,明白了,谢谢,望狐友们(菜鸟级别)的注意了~    呵呵,俺也是菜鸟一个 ~~
如果从窗口中引入保存的窗口模板时,能连窗口名一起引入就没有这个问题了 ··· 

[此贴子已经被作者于2009-8-27 18:35:20编辑过]
4楼
yangming 发表于:2009/8/27 17:49:00
赞一个,谢谢!
5楼
mr725 发表于:2009/8/27 17:59:00
以下是引用yangming在2009-8-27 17:49:00的发言:
赞一个,谢谢!

呵呵~  应用了yang版您的获取显示列的代码,还有:
原来afterload:中这段代码忘了删除,重新上传了~  
if bm.contains("Excel模板|") then
    bm = bm.replace("Excel模板|","")
end if
if bm.contains("|Excel模板") then
    bm = bm.replace("|Excel模板","")
end if

[此贴子已经被作者于2009-8-27 18:30:41编辑过]
共5 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03296 s, 3 queries.