选择显示字体大小

vsprint打印实例

 

option explicit

public function formatdata2(byval data1 as double, byval data2 as double) as string
    dim dt1, dt2 as double
    dt1 = data1
    dt2 = data2
    if dt1 = 0 or dt1 = 0# or dt2 = 0 or dt2 = 0# then
        formatdata2 = "0.00"
    else
        formatdata2 = format(round(dt1 / dt2, 2), "0.00")
    end if
end function

public sub print_jian_anhuizong(byref printctl as vsprinter, byval strtable as string, byval strtitle)
    dim con as new adodb.connection
    dim rst as new adodb.recordset
    dim str_table as string
    dim str_title as string
    dim strsql as string
    dim icurrent as integer
    dim cols as integer '页面表格的列数
    dim icurrenrows as integer '页面表格当前显示的总行数
    dim rows as long '总行数
    dim trows as long '页面表格总行数
    dim pages as integer '总页数
    dim ipage as integer '当前页面
    dim ilastrows as integer '整页显示后剩余的行数
    dim irow as long '当前行的位置
on error goto err1
    str_table = strtable
    str_title = strtitle
    con.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & strconnection & ";persist security info=false"
    con.open
    strsql = "select nn,name,unit,pricezhijiegongcheng,pricezhijie,pricerengong,pricecailiao,pricejixie," & _
            "priceqitazhijie,pricexianchang,pricejianjie,pricejihualirun,priceshuijin,priceshashijiacha ,price1 from " & str_table & " order by nn"
    rst.cursortype = adopenkeyset
    rst.locktype = adlockoptimistic
    rst.open strsql, con, , , adcmdtext
    cols = 13
    if not rst.bof and not rst.eof then
        '获得总的记录数rows
        rst.movefirst
        do while not rst.eof
            rows = rows + 1
            rst.movenext
        loop
        '重新设置行的位置为第一条记录
        rst.movefirst
        '设置总的页面数
        if rows <= 18 then '总行数小于等于页面显示的总行数
            pages = 1
            icurrenrows = rows
            ilastrows = 0
        else '总行数大于页面显示的总行数
            if rows mod 18 = 0 then '总行数等于页面显示的总行数倍数
                pages = int(rows / 18)
                ilastrows = 0
            else '总行数不等于页面显示的总行数倍数
                pages = int(rows / 18) + 1
                ilastrows = rows mod 18
            end if
            icurrenrows = 18
        end if
        ipage = 1 '设置当前页面为第一页面
        irow = 0 '设置当前行位置为空
        '
        with printctl
            .orientation = orlandscape '设置横向打印
            .tableborder = tball
            '设置页面四边的边距
            .margintop = 1400
            .marginbottom = 1400
            .marginleft = 1400
            .marginright = 1400
            '设置字体名字
'*************************************开始打印文档的内容*************************************            .startdoc
            .startdoc
            .tablepen = 20
            for ipage = 1 to pages
                 '设置标题
                .fontsize = 14
                .fontbold = true
                .textalign = tacentermiddle
                .paragraph = str_title
                .paragraph = ""
                .fontbold = false
                .fontsize = 10
                '设置页面表格
                .fontsize = 9
                .starttable
                .textalign = tarightmiddle
                .paragraph = "单位: 元"
                .starttable
                .tablecell(tccols) = cols
                if ipage = pages and ilastrows <> 0 then
                    trows = ilastrows + 2
                else
                     trows = icurrenrows + 2
                end if
                .tablecell(tcrows) = trows
                '///
                .tablecell(tcrowheight) = 400
                .tablecell(tccolwidth, , 1) = 600
                .tablecell(tccolwidth, , 2) = 2600
                .tablecell(tccolwidth, , 3) = 1000
                .tablecell(tccolwidth, , 4) = 1000
                .tablecell(tccolwidth, , 5) = 1000
                .tablecell(tccolwidth, , 6) = 1000
                .tablecell(tccolwidth, , 7) = 1000
                .tablecell(tccolwidth, , 8) = 1000
                .tablecell(tccolwidth, , 9) = 1000
                .tablecell(tccolwidth, , 10) = 1000
                .tablecell(tccolwidth, , 11) = 1000
                .tablecell(tccolwidth, , 12) = 1000
                .tablecell(tccolwidth, , 13) = 1000
                .tablecell(tccolspan, 1, 4) = 10
                .tablecell(tcrowspan, 1, 1) = 2
                .tablecell(tcrowspan, 1, 2) = 2
                .tablecell(tcrowspan, 1, 3) = 2
                '///
                .tablecell(tctext, 1, 1) = "序号"
                .tablecell(tctext, 1, 2) = "工程单价名称"
                .tablecell(tctext, 1, 3) = "单价"
                .tablecell(tctext, 1, 4) = "其中"
                .tablecell(tctext, 2, 4) = "人工费"
                .tablecell(tctext, 2, 5) = "材料费"
                .tablecell(tctext, 2, 6) = "机械费"
                .tablecell(tctext, 2, 7) = "其他直接费"
                .tablecell(tctext, 2, 8) = "现场经费"
                .tablecell(tctext, 2, 9) = "直接工程费"
                .tablecell(tctext, 2, 10) = "间接费"
                .tablecell(tctext, 2, 11) = "计划利润"
                .tablecell(tctext, 2, 12) = "税金"
                .tablecell(tctext, 2, 13) = "材差"
                '///
                .tablecell(tcalign, 1, 1, 1, 13) = tacentermiddle '标题行居中对齐
                .tablecell(tcalign, 2, 4, 2, 13) = tacentermiddle '标题行居中对齐
               
                .tablecell(tcalign, 3, 1, trows, 1) = tacentermiddle '第一列居中对齐
                .tablecell(tcalign, 3, 2, trows, 2) = taleftmiddle '第二列居中左对齐
                .tablecell(tcalign, 3, 3, trows, 13) = tarightmiddle '其他列居中右对齐
'*************************************向每一页面添加数据*************************************
                icurrent = 0
                do while not rst.eof
                    irow = irow + 1
                    '当当前页面数据添加完后退出循环,开始下一页面
                    if icurrent <> 0 and icurrent mod 18 = 0 then
                        exit do
                    end if
                    .tablecell(tctext, 3 + icurrent, 1) = rst.fields("nn") & ""
                    .tablecell(tctext, 3 + icurrent, 2) = rst.fields("name") & ""
                    .tablecell(tctext, 3 + icurrent, 3) = formatdata2(val(rst.fields("price1") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 4) = formatdata2(val(rst.fields("pricerengong") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 5) = formatdata2(val(rst.fields("pricecailiao") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 6) = formatdata2(val(rst.fields("pricejixie") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 7) = formatdata2(val(rst.fields("priceqitazhijie") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 8) = formatdata2(val(rst.fields("pricexianchang") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 9) = formatdata2(val(rst.fields("pricezhijiegongcheng") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 10) = formatdata2(val(rst.fields("pricejianjie") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 11) = formatdata2(val(rst.fields("pricejihualirun") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 12) = formatdata2(val(rst.fields("priceshuijin") & ""), val(rst.fields("unit") & ""))
                    .tablecell(tctext, 3 + icurrent, 13) = formatdata2(val(rst.fields("priceshashijiacha") & ""), val(rst.fields("unit") & ""))
                    rst.movenext
                    icurrent = icurrent + 1
                loop
                .endtable
                '判断当前记录的位置是否为最后一条,如果不是最后一条,开始新的一页
                if irow < rows then
                    .newpage '开始新的一页
                end if
            next ipage
'*************************************结束打印文档*************************************
            .enddoc
        end with
    else
        msgbox "没有要打印的数据", vbokonly + vbinformation
    end if
    rst.close
    con.close
    set rst = nothing
    set con = nothing
    exit sub
err1:
    msgbox err.description, vbokonly + vbinformation, "提示"
end sub



 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons