以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]打印 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=86205) |
||||
-- 作者:江南小城 -- 发布时间:2016/6/13 9:11:00 -- [求助]打印 老师,打印按钮有问题,望老师帮忙修改。感谢
此主题相关图片如下:图像 1.png |
||||
-- 作者:大红袍 -- 发布时间:2016/6/13 9:40:00 -- Dim dst As Table = Tables("进销存_Table6") Dim clb As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox2") Dim nbox1 As WinForm.NumericComboBox = e.Form.Controls("NumericComboBox1") Dim rbt As WinForm.RadioButton = e.Form.Controls("RadioButton1") Dim dt As DataTable = dst.DataTable If nbox1.value > dst.DataTable.DataCols.Count Then msgbox("合并列数不能大于表列数!",64,"提示") Else Dim bstr,kkk,kk As String Dim r,c,i1,i2,i3,m,n,n2,i,rm,rm2,ci As Integer Dim v As Integer = e.Form.Controls("NumericComboBox2").value \'表头高 Dim vv As Integer = e.Form.Controls("NumericComboBox3").value \'行高 Dim s,ss,z As String Dim s2 As String = "" Dim ss2 As String = "__________" Dim doc As New PrintDoc \'定义一个报表 For i=0 To e.Form.Controls("NumericComboBox4").value-1 Doc.Columns.Add() Next Doc.PageSetting.LeftMargin = 10 \'设置左边距 Doc.PageSetting.RightMargin = 10 \'设置右边距 Doc.PageSetting.TopMargin = 5 \'设置上边距 Doc.PageSetting.BottomMargin = 5 \'设置下边距 Dim rt As New prt.RenderTable() \'定义一个表格对象 rt.Style.Gridlines.All = New prt.Linedef(e.Form.Controls("ColorLabel2").Color) \'灰色网格线 rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 rt.Style.Spacing.top = 5 \'表格上边距为5 If not e.Form.Controls("CheckBox3").Checked Then rt.Width = "Auto" \'表宽等于各列设置值之和 rt.CanSplitHorz = True \'允许表格在水平方向换页 End If \'设置标题 If e.Form.Controls("NumericComboBox4").value <= 1 Then Dim rs As New prt.RenderText() \'定义一个文本对象 rs.Text = e.Form.Controls("TextBox13").value \'设置标题 rs.Style.Font = New Font("宋体", 15 , FontStyle.Bold) \'设置标题字体 rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 doc.Body.Children.Add(rs) \'将标题对象加入到表格中 End If doc.Body.Children.Add(rt) \'将表格对象加入到报表中 \'----------------------------------------------------------------- If e.Form.Controls("ComboBox5").value ="纵向" OrElse e.Form.Controls("ComboBox5").value = "" doc.PageSetting.Landscape = False \'打印方向 Else doc.PageSetting.Landscape = True \'横向打印方向 End If \'求得表头层数 For Each dc As DataCol In dt.DataCols kkk = kkk & "," & dc.name i2 = dc.name.split("_").length-1 i1 = Math.Max(i1,i2) Next For Each dc As DataCol In dt.DataCols If clb.GetItemChecked(c) Then \'判断选择列,真,导出,假,隐藏列 ss = dc.name & "__________" \'求得列表头最大宽度 For i = 1 To Len(ss.split("_")(0)) m = Asc(Mid(ss, i, 1)) If m >= 0 And m <128 Then \' 英文 n = n + 1 Else \' 中文 n = n + 2 End If Next i3 = Math.Max(i3,n) For i=0 To i1 If v>0 Then rt.Rows(r).Height = v \'表头高度 End If rt.Cells(i,c).Text = ss.split("_")(i) \'设置表头内容 If ss2.split("_")(i)=ss.split("_")(i) And ss2.split("_")(i)<>"" And c<dt.datacols.count Then kk = kkk.Replace(ss.split("_")(i),"@") rt.Cells(i,c-1).SpanCols = len(kk)-len(kk.Replace("@","")) \'合并多表头 End If Next r = i1 For Each dr As DataRow In dt.Datarows s = dr(dc) \'求得当前列各行中最大宽度 For i = 1 To Len(s) m = Asc(Mid(s, i, 1)) If m >= 0 And m <128 Then \' 英文 n2 = n2 + 1 Else \' 中文 n2 = n2 + 2 End If Next i3 = Math.Max(i3,n2) r +=1 \'行开始 \'设置单元格值 rt.Cells(r,c).Text = s z = "" If c>1 And rbt.Checked Then For i=1 To c z = z & rt.cells(r,i).text Next s = z End If \'合并指定前N列 If c <= nbox1.value Then If s <> s2 Or r-i1=dt.DataRows.Count Then If s=s2 Then rm2 = rm2+1 End If If rm2 <> 0 And s2<>"" And s2<>"0" Then rt.Cells(rm,c).SpanRows = rm2 End If s2 = s rm = r rm2 = 1 Else rm2 +=1 End If End If If vv>0 Then rt.Rows(r).Height = vv \'设置行高 End If n2 = 0 \'完成一行后初始化条件 Next If rt.Cells(i1,c).Text="" Then rt.Cells(0,c).SpanRows = i1+1 \'合并单表头 End If rt.Cols(c).Width = (i3+2.5)*1.8 \'设置列宽 Else rt.Cols(c).Width = 0 \'隐藏列 End If \'完成一列后初始化条件 ss2 = ss & ss2 i3 = 0 n = 0 c +=1 r = i1 Next \'设置页眉 Dim rx As New prt.RenderTable rx.Cells(0,0).Text = e.Form.Controls("TextBox14").value If e.Form.Controls("NumericComboBox4").value <= 1 Then rx.Cells(0,1).Text = e.Form.Controls("TextBox16").value rx.Style.FontSize = 9 \'字体大小为9磅 Else rx.Cells(0,1).Text = e.Form.Controls("TextBox5").value \'当作标题 rx.Style.Font = New Font("宋体", 15 , FontStyle.Bold) \'设置标题字体 End If \'-------------------------------------------------------------------------------------------- rx.Cells(0,2).Text = e.Form.Controls("TextBox17").value rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right If e.Form.Controls("CheckBox1").Checked Then rx.Style.Borders.Bottom = prt.LineDef.Default \'设置底边框 End If rx.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米 Doc.PageHeader = rx \'作为页眉使用 \'设置页脚 Dim ry As New prt.RenderTable ry.Cells(0,0).Text = e.Form.Controls("TextBox15").value ry.Cells(0,1).Text = e.Form.Controls("TextBox18").value ry.Cells(0,2).Text = e.Form.Controls("TextBox19").value ry.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left ry.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center ry.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right If e.Form.Controls("CheckBox2").Checked Then ry.Style.Borders.Top = prt.LineDef.Default \'设置底边框 End If ry.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米 ry.Style.FontSize = 9 \'字体大小为9磅 Doc.PageFooter = ry \'作为页脚使用 rt.RowGroups(0,i1+1).Header = prt.TableHeaderEnum.All \'设置表头组 rt.RowGroups(0,i1+1).Style.BackColor = e.Form.Controls("ColorLabel1").Color \'表头底色 Doc.Preview() \'预览报表 End If |
||||
-- 作者:江南小城 -- 发布时间:2016/6/13 10:52:00 -- 老师,能否打印复选后的数据。 |
||||
-- 作者:大红袍 -- 发布时间:2016/6/13 11:11:00 --
|
||||
-- 作者:江南小城 -- 发布时间:2016/6/13 14:31:00 -- 老师,在打印预览中缺少开票日期列的表头。 此主题相关图片如下:图像 2.png |
||||
-- 作者:大红袍 -- 发布时间:2016/6/13 14:33:00 -- 上传具体实例。 |
||||
-- 作者:江南小城 -- 发布时间:2016/6/13 15:21:00 --
|
||||
-- 作者:大红袍 -- 发布时间:2016/6/13 15:59:00 -- Dim dst As Table = Tables("进销存_Table6") Dim clb As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox2") Dim nbox1 As WinForm.NumericComboBox = e.Form.Controls("NumericComboBox1") Dim rbt As WinForm.RadioButton = e.Form.Controls("RadioButton1") Dim dt As DataTable = dst.DataTable If nbox1.value > dst.DataTable.DataCols.Count Then msgbox("合并列数不能大于表列数!",64,"提示") Else Dim bstr,kkk,kk As String Dim r,c,i1,i2,i3,m,n,n2,i,rm,rm2,ci As Integer Dim v As Integer = e.Form.Controls("NumericComboBox2").value \'表头高 Dim vv As Integer = e.Form.Controls("NumericComboBox3").value \'行高 Dim s,ss,z As String Dim s2 As String = "" Dim ss2 As String = "__________" Dim doc As New PrintDoc \'定义一个报表 For i=0 To e.Form.Controls("NumericComboBox4").value-1 Doc.Columns.Add() Next Doc.PageSetting.LeftMargin = 10 \'设置左边距 Doc.PageSetting.RightMargin = 10 \'设置右边距 Doc.PageSetting.TopMargin = 5 \'设置上边距 Doc.PageSetting.BottomMargin = 5 \'设置下边距 Dim rt As New prt.RenderTable() \'定义一个表格对象 rt.Style.Gridlines.All = New prt.Linedef(e.Form.Controls("ColorLabel2").Color) \'灰色网格线 rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中 rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中 rt.Style.Spacing.top = 5 \'表格上边距为5 If not e.Form.Controls("CheckBox3").Checked Then rt.Width = "Auto" \'表宽等于各列设置值之和 rt.CanSplitHorz = True \'允许表格在水平方向换页 End If \'设置标题 If e.Form.Controls("NumericComboBox4").value <= 1 Then Dim rs As New prt.RenderText() \'定义一个文本对象 rs.Text = e.Form.Controls("TextBox13").value \'设置标题 rs.Style.Font = New Font("宋体", 15 , FontStyle.Bold) \'设置标题字体 rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'标题内容水平居中 doc.Body.Children.Add(rs) \'将标题对象加入到表格中 End If doc.Body.Children.Add(rt) \'将表格对象加入到报表中 \'----------------------------------------------------------------- If e.Form.Controls("ComboBox6").value ="纵向" OrElse e.Form.Controls("ComboBox6").value = "" doc.PageSetting.Landscape = False \'打印方向 Else doc.PageSetting.Landscape = True \'横向打印方向 End If \'求得表头层数 For Each dc As Col In dst.Cols kkk = kkk & "," & dc.name i2 = dc.name.split("_").length-1 i1 = Math.Max(i1,i2) Next For Each tc As Col In dst.Cols Dim dc As DataCol = tc.DataCol If clb.GetItemChecked(c) Then \'判断选择列,真,导出,假,隐藏列 ss = dc.name & "__________" \'求得列表头最大宽度 For i = 1 To Len(ss.split("_")(0)) m = Asc(Mid(ss, i, 1)) If m >= 0 And m <128 Then \' 英文 n = n + 1 Else \' 中文 n = n + 2 End If Next i3 = Math.Max(i3,n) For i=0 To i1 If v>0 Then rt.Rows(r).Height = v \'表头高度 End If rt.Cells(i,c).Text = ss.split("_")(i) \'设置表头内容 If ss2.split("_")(i)=ss.split("_")(i) And ss2.split("_")(i)<>"" And c<dt.datacols.count Then kk = kkk.Replace(ss.split("_")(i) & "_","@") rt.Cells(i,c-1).SpanCols = len(kk)-len(kk.Replace("@","")) \'合并多表头 End If Next r = i1 For Each cr As Row In dst.GetCheckedRows Dim dr As DataRow = cr.DataRow s = dr(dc) \'求得当前列各行中最大宽度 For i = 1 To Len(s) m = Asc(Mid(s, i, 1)) If m >= 0 And m <128 Then \' 英文 n2 = n2 + 1 Else \' 中文 n2 = n2 + 2 End If Next i3 = Math.Max(i3,n2) r +=1 \'行开始 \'设置单元格值 rt.Cells(r,c).Text = s z = "" If c>1 And rbt.Checked Then For i=1 To c z = z & rt.cells(r,i).text Next s = z End If \'合并指定前N列 If c <= nbox1.value Then If s <> s2 Or r-i1=dt.DataRows.Count Then If s=s2 Then rm2 = rm2+1 End If If rm2 <> 0 And s2<>"" And s2<>"0" Then rt.Cells(rm,c).SpanRows = rm2 End If s2 = s rm = r rm2 = 1 Else rm2 +=1 End If End If If vv>0 Then rt.Rows(r).Height = vv \'设置行高 End If n2 = 0 \'完成一行后初始化条件 Next If rt.Cells(i1,c).Text="" Then rt.Cells(0,c).SpanRows = i1+1 \'合并单表头 End If rt.Cols(c).Width = (i3+2.5)*1.8 \'设置列宽 Else rt.Cols(c).Width = 0 \'隐藏列 End If \'完成一列后初始化条件 ss2 = ss & ss2 i3 = 0 n = 0 c +=1 r = i1 Next \'设置页眉 Dim rx As New prt.RenderTable rx.Cells(0,0).Text = e.Form.Controls("TextBox14").value If e.Form.Controls("NumericComboBox4").value <= 1 Then rx.Cells(0,1).Text = e.Form.Controls("TextBox16").value rx.Style.FontSize = 9 \'字体大小为9磅 Else rx.Cells(0,1).Text = e.Form.Controls("TextBox5").value \'当作标题 rx.Style.Font = New Font("宋体", 15 , FontStyle.Bold) \'设置标题字体 End If \'-------------------------------------------------------------------------------------------- rx.Cells(0,2).Text = e.Form.Controls("TextBox17").value rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left rx.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center rx.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right If e.Form.Controls("CheckBox1").Checked Then rx.Style.Borders.Bottom = prt.LineDef.Default \'设置底边框 End If rx.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米 Doc.PageHeader = rx \'作为页眉使用 \'设置页脚 Dim ry As New prt.RenderTable ry.Cells(0,0).Text = e.Form.Controls("TextBox15").value ry.Cells(0,1).Text = e.Form.Controls("TextBox18").value ry.Cells(0,2).Text = e.Form.Controls("TextBox19").value ry.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Left ry.Cols(1).Style.TextAlignHorz = prt.AlignHorzEnum.Center ry.Cols(2).Style.TextAlignHorz = prt.AlignHorzEnum.right If e.Form.Controls("CheckBox2").Checked Then ry.Style.Borders.Top = prt.LineDef.Default \'设置底边框 End If ry.CellStyle.Spacing.Bottom = 0.5 \'底端内容缩进0.5毫米 ry.Style.FontSize = 9 \'字体大小为9磅 Doc.PageFooter = ry \'作为页脚使用 rt.RowGroups(0,i1+1).Header = prt.TableHeaderEnum.All \'设置表头组 rt.RowGroups(0,i1+1).Style.BackColor = e.Form.Controls("ColorLabel1").Color \'表头底色 Doc.Preview() \'预览报表 End If |
||||
-- 作者:江南小城 -- 发布时间:2016/6/13 17:31:00 -- 谢谢老师 |