以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  批量打印名片大小的出入证  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=109762)

--  作者:刘林
--  发布时间:2017/11/18 20:54:00
--  批量打印名片大小的出入证
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim Rows As List(of Row) = Tables("学生信息").GetCheckedRows()
Dim rm As prt.RenderEmpty
Doc.PageSetting.LeftMargin = 5 \'设置左边距
Doc.PageSetting.RightMargin = 5 \'设置右边距
Doc.PageSetting.TopMargin = 10 \'设置上边距
Doc.PageSetting.BottomMargin = 10 \'设置下边距
rm = new prt.RenderEmpty \'定义一个新的空对象
\' rm.BreakBefore = prt.BreakEnum.Page \'打印前换页
doc.Body.Children.Add(rm)
rt = New prt.RenderTable
rt.Cols(0).Width = 92
rt.Cols(1).width = 92
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中
rt.Style.Gridlines.All = New prt.Linedef(Color.black) \'灰色网格线
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.black)
rt.Style.Spacing.Bottom = 2
rt.CellStyle.Spacing.All = 1
rt.Style.Font = New Font("宋体", 25, FontStyle.Bold)
Dim i As Integer
Dim j As Integer
For r As Integer= 0 To Rows.Count-1
    rt.Cells(math.ceiling(r\\2),r Mod 2).Text = Rows(r)("学生姓名")
\'rt.Cells(math.ceiling(r\\2),r Mod 2).Image = GetImage(Rows(r)("相片"))
    rt.Rows(math.ceiling(r\\2)).Height=52
Next
doc.Body.Children.Add(rt)
doc.preview()


老师,我想用代码在学生信息表中直接打印出入证,格式如附件,研究不走了,这该怎样做?
图片点击可在新窗口打开查看此主题相关图片如下:111.png
图片点击可在新窗口打开查看

--  作者:刘林
--  发布时间:2017/11/18 20:54:00
--  
这个附件是在word中做的
--  作者:rjh4078
--  发布时间:2017/11/19 9:10:00
--  
相纸多大?如果一行2个,每个证件的大小和元素固定好 用大循环走一边 大概思路

定义相纸大小
for r as row in tables("学生信息").getcheckedrows
定义每个证件大小
加入证件元素

next

预览



--  作者:刘林
--  发布时间:2017/11/19 9:49:00
--  
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim Rows As List(of Row) = Tables("学生信息").GetCheckedRows()
Dim rm As prt.RenderEmpty
Doc.PageSetting.LeftMargin = 5 \'设置左边距
Doc.PageSetting.RightMargin = 5 \'设置右边距
Doc.PageSetting.TopMargin = 10 \'设置上边距
Doc.PageSetting.BottomMargin = 10 \'设置下边距
rm = new prt.RenderEmpty \'定义一个新的空对象
doc.Body.Children.Add(rm)
rt = New prt.RenderTable
rt.Cols(0).Width = 42
rt.Cols(1).width = 50
rt.Cols(2).Width = 42
rt.Cols(3).width = 50
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居中
rt.Style.Gridlines.All = New prt.Linedef(Color.black) \'灰色网格线
rt.Style.GridLines.All = New prt.LineDef(0.3,Color.black)
rt.Style.Spacing.Bottom = 2
rt.CellStyle.Spacing.All = 1
rt.Style.Font = New Font("宋体", 15, FontStyle.Bold)
Dim i As Integer
Dim j As Integer
For r As Integer= 0 To Rows.Count-1
    Dim l As Integer = r Mod 2
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居
    rt.Rows((math.ceiling(r\\2))*4).Height=13
    rt.Rows((math.ceiling(r\\2))*4+1).Height=13
    rt.Rows((math.ceiling(r\\2))*4+2).Height=13
    rt.Rows((math.ceiling(r\\2))*4+3).Height=13
    rt.Cells((math.ceiling(r\\2))*4, 2*l).Text = Rows(r)("学校名称")
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.left \'水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center
    rt.Cells((math.ceiling(r\\2))*4+1, 3^l).Text = "姓名:" & Rows(r)("学生姓名")
    rt.Cells((math.ceiling(r\\2))*4+2, 3^l).Text = "班级:" & Rows(r)("班级")
    rt.Cells((math.ceiling(r\\2))*4+3, 3^l).Text = "备注:" & Rows(r)("就读方式")
    rt.Cells((math.ceiling(r\\2))*4+1,2*l).Image = GetImage(Rows(r)("相片"))
    rt.Cells((math.ceiling(r\\2))*4,2*l).SpanCols = 2
    rt.Cells((math.ceiling(r\\2))*4+1,2*l).Spanrows = 3
Next
doc.Body.Children.Add(rt)
doc.preview()
现在写成这样,基本实现了想法,但现在还有几个问题,一是相片不能填入?记录中有相片。二是如何将内部网格线去掉只留外框线,三是根据就读方式不同来打印字的颜色,住为红色,走校为蓝色

--  作者:有点甜
--  发布时间:2017/11/19 15:45:00
--  

1、写全路径

 

rt.Cells((math.ceiling(r\\2))*4+1,2*l).Image = GetImage(projectPath & "attachments/" & Rows(r)("相片"))

 

2、加上代码

 

    rt.Cells((math.ceiling(r\\2))*4+1, 3*l).Style.Borders.Bottom = New prt.LineDef(0.3, Color.white)
    rt.Cells((math.ceiling(r\\2))*4+1, 3*l).Style.Borders.left = New prt.LineDef(0.3, Color.white)
    rt.Cells((math.ceiling(r\\2))*4+1, 3*l).Style.Borders.top = New prt.LineDef(0.3, Color.white)

 

3、设置样式

 

    rt.Cells((math.ceiling(r\\2))*4+3, 3^l).Style.TextColor = color.red


--  作者:刘林
--  发布时间:2017/11/19 21:01:00
--  
Dim doc As New PrintDoc
Dim rt As Prt.RenderTable
Dim rx As prt.RenderText
Dim Rows As List(of Row) = Tables("学生信息").GetCheckedRows()
Dim rm As prt.RenderEmpty
Doc.PageSetting.LeftMargin = 5 \'设置左边距
Doc.PageSetting.RightMargin = 5 \'设置右边距
Doc.PageSetting.TopMargin = 10 \'设置上边距
Doc.PageSetting.BottomMargin = 10 \'设置下边距
rm = new prt.RenderEmpty \'定义一个新的空对象
doc.Body.Children.Add(rm)
rt = New prt.RenderTable
rt.Cols(0).Width = 42
rt.Cols(1).width = 50
rt.Cols(2).Width = 42
rt.Cols(3).width = 50
rt.Style.Spacing.Bottom = 2
rt.CellStyle.Spacing.All = 1
Dim i As Integer
Dim j As Integer
For r As Integer= 0 To Rows.Count-1
    Dim l As Integer = r Mod 2
If Rows(r)("就读方式")= "住校"
rt.Style.TextColor = Color.Red 
Else
rt.style.textcolor = Color.blue
End If
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center \'垂直居
    rt.Rows((math.ceiling(r\\2))*4).Height=13
    rt.Rows((math.ceiling(r\\2))*4+1).Height=13
    rt.Rows((math.ceiling(r\\2))*4+2).Height=13
    rt.Rows((math.ceiling(r\\2))*4+3).Height=13
    rt.Style.GridLines.All = New Prt.LineDef(0.1, Color.Black)
    rt.Style.GridLines.Horz = new Prt.LineDef(Color.white)
    rt.Style.GridLines.Vert = new Prt.LineDef(Color.white)
    rt.Style.Font = New Font("黑体", 16, FontStyle.Bold) \'
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'
    rt.Cells((math.ceiling(r\\2))*4, 2*l).Text = Rows(r)("学校名称")
    rt.Style.Font = New Font("宋体", 15, FontStyle.Bold)
    rt.Style.TextAlignHorz = prt.AlignHorzEnum.left 
    rt.Style.TextAlignVert = prt.AlignVertEnum.Center
    rt.Cells((math.ceiling(r\\2))*4+1, 3^l).Text = "姓名:" & Rows(r)("学生姓名")
    rt.Cells((math.ceiling(r\\2))*4+2, 3^l).Text = "班级:" & Rows(r)("班级")
    rt.Cells((math.ceiling(r\\2))*4+3, 3^l).Text = "备注:" & Rows(r)("就读方式")
    rt.Cells((math.ceiling(r\\2))*4+1,2*l).Image = GetImage(projectPath & "attachments/" & Rows(r)("相片"))
    rt.Cells((math.ceiling(r\\2))*4,2*l).SpanCols = 2
    rt.Cells((math.ceiling(r\\2))*4+1,2*l).Spanrows = 3
Next
doc.Body.Children.Add(rt)
doc.preview()


老师,现在还个问题,我是想 rt.Cells((math.ceiling(r\\2))*4, 2*l).Text = Rows(r)("学校名称")的内容在表格里居中,字号大一点用黑体,单独设格式,
rt.Cells((math.ceiling(r\\2))*4+1, 3^l).Text = "姓名:" & Rows(r)("学生姓名")
rt.Cells((math.ceiling(r\\2))*4+2, 3^l).Text = "班级:" & Rows(r)("班级")
 rt.Cells((math.ceiling(r\\2))*4+3, 3^l).Text = "备注:" & Rows(r)("就读方式")
这三个内容表格靠左对齐
另外如果记录中为走校时用蓝色字,住校时用红色字,按上面做做部是红色,单独如何设置某单元格的字体字号呢?

--  作者:有点甜
--  发布时间:2017/11/19 21:09:00
--  

对齐参考

 

http://www.foxtable.com/webhelp/scr/1170.htm

 

设置字体同样

 

http://www.foxtable.com/webhelp/scr/1179.htm

 

如果要:备注、就读方式分开不同的颜色,你应该分开成两个单元格赋值


--  作者:刘林
--  发布时间:2017/11/19 21:16:00
--  
找到到办法了,谢谢,有什么问题再请教