-- 作者:mr725
-- 发布时间:2009/8/27 17:09:00
-- 狐表-通用打印窗口 打遍项目中所有的表◎
在任何狐表项目中引用本窗口(看2楼注意事项,附件已重新更正了),或应用本窗口中的控件代码,就可以打印你想要打印的表了~ afterload代码修改重上传! 欢迎大家纠错~
有两个窗口控件: 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编辑过]
|