以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 打印时报错,但是打印内容,打印动作没有问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=115707) |
-- 作者:873773115 -- 发布时间:2018/3/13 8:23:00 -- 打印时报错,但是打印内容,打印动作没有问题 打印时会报错 此主题相关图片如下:微信图片_20180313082141.jpg |
-- 作者:873773115 -- 发布时间:2018/3/13 8:25:00 -- 请老师帮忙看下 |
-- 作者:有点甜 -- 发布时间:2018/3/13 8:38:00 -- 贴出你写的代码。如果是office文件的打印,尽量用vba处理
http://www.foxtable.com/webhelp/scr/2121.htm
|
-- 作者:873773115 -- 发布时间:2018/3/13 8:43:00 -- Case "送货单" Relations.Delete("asdf") Dim dt3 As Table = Tables("出库主表_出库主表") Dim ids As String If dt3.Current IsNot Nothing Then With Tables("出库主表_出库主表") If .TopPosition > -1 Then \'如果选定区域包括数据行 For i As Integer = .TopPosition To .BottomPosition ids = ids & ",\'" & dt3.Rows(i)("出库单号") & "\'" .Rows(i)("是否打印") = True Next End If End With ids= ids.Trim(",") Dim cmd As new SQLCommand Dim dt As DataTable cmd.C cmd.CommandText = "select * fro m {出库明细表} where 出库单号 in (" & ids & ")" dt = cmd.ExecuteReader Tables("出库主表_出库子表").DataSource = dt Tables("出库主表_出库子表").Sort = "出库序号" Relations.Add("asdf",DataTables("出库主表_出库主表").DataCols("出库单号"),DataTables("出库主表_出库子表").DataCols("出库单号")) Dim Book As New XLS.Book(ProjectPath & "Attachments\\送货单.xls") \'打开模板 Dim fl As String = ProjectPath & "Reports\\送货单.xls" Dim rt As prt.RenderText Dim Sheet As XLS.Sheet = Book.Sheets(0) With Sheet.PrintSetting .LandScape = False .MarginLeft = 8 \'左右边距设为20毫米 .MarginRight = 8 .MarginTop = 8 \'上下边距设为15毫米 .MarginBottom = 8 End With Book.Build() \'生成报表 Book.Save(fl) Dim Proc As New Process Proc.File = fl Proc.Verb = "Print" \'指定动作 Proc.Start() End If |
-- 作者:873773115 -- 发布时间:2018/3/13 8:44:00 -- 甜老师,用VBA该怎么写呢? 很奇怪的是 有的电脑会报错,有的又不会 |
-- 作者:有点甜 -- 发布时间:2018/3/13 8:45:00 -- 如
Dim App As New MSExcel.Application |
-- 作者:873773115 -- 发布时间:2018/3/13 8:56:00 -- VBA的打印代码和EXCEL模板的代码 看起来完全不一样 现在急着用,一时还不会用VBA 甜老师,有其他方法能解决应用程序传输错误吗? |
-- 作者:有点甜 -- 发布时间:2018/3/13 9:02:00 -- Dim Proc As New Process
改成6楼代码即可。 |
-- 作者:873773115 -- 发布时间:2018/3/14 10:41:00 -- Relations.Delete("asdf") Dim dt3 As Table = Tables("订单主表_订单主表") Dim ids As String If dt3.Current IsNot Nothing Then With Tables("订单主表_订单主表") If .TopPosition > -1 Then \'如果选定区域包括数据行 For i As Integer = .TopPosition To .BottomPosition ids = ids & ",\'" & dt3.Rows(i)("单号") & "\'" Next End If End With ids= ids.Trim(",") Dim cmd As new SQLCommand Dim dt As DataTable cmd.C cmd.CommandText = "select * fro m {订单明细表} where 单号 in (" & ids & ")" dt = cmd.ExecuteReader Tables("订单主表_订单子表").DataSource = dt Tables("订单主表_订单子表").Sort = "序号" Relations.Add("asdf",DataTables("订单主表_订单主表").DataCols("单号"),DataTables("订单主表_订单子表").DataCols("单号")) Dim Book As New XLS.Book(ProjectPath & "Attachments\\订单表.xls") \'打开模板 Dim fl As String = ProjectPath & "Reports\\订单表.xls" Dim rt As prt.RenderText Dim Sheet As XLS.Sheet = Book.Sheets(0) With Sheet.PrintSetting .LandScape = False .MarginLeft = 8 \'左右边距设为20毫米 .MarginRight = 8 .MarginTop = 8 \'上下边距设为15毫米 .MarginBottom = 8 End With Book.Build() \'生成报表 Book.Save(fl) Dim App As New MSExcel.Application Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl) Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) Dim EndRow As Integer = Ws.Range("H65536").End(MSExcel.XlDirection.xlUp).Row \'对A列从第1行开始向下查找,直到找到最后一个非空单元格为止,并得到其行号.也就是有内容的开始行 Dim FirstRow As Integer = Ws.Range("A1").End(MSExcel.XlDirection.xlDown).Row \'对A列从第1行开始向下查找,直到找到最后一个非空单元格为止,并得到其行号.也就是有内容的开始行 Ws.Cells.PageBreak = MSExcel.XlPageBreak.xlPageBreakNone\'清除所有分页符 For i As Integer = FirstRow +15 To EndRow Step 18 \'每18行就分页 Ws.Rows(i).PageBreak = MSExcel.XlPageBreak.xlPageBreakManual With Ws.PageSetup .PrintArea = "A" & FirstRow - 3 & ":h" & Endrow \'打印工作表的指定区域 \'设置页面 .LeftMargin = 10 \'页面左边距 .RightMargin = 10\'页面右边距 .TopMargin = 10 \'页面顶部边距 .BottomMargin = 10 \'页面底部边距 .CenterHorizontally = True \'页面水平居中 .CenterVertically = True \'页面垂直居中 \'设置页 .Orientation = MSExcel.xlPageOrientation.xlPortrait \'\'缩放打印 \'.Zoom = True \'以下设置将缩印在一页内 .FitToPagesWide = 1 \'按照1页的宽度打印 .FitToPagesTall = 1 \'按照1页的高度打印 End With Next App.Visible = True Ws.PrintPreview App.Quit End If 请老师看下 这段代码无法实现18行分页是怎么回事呢
|
-- 作者:有点甜 -- 发布时间:2018/3/14 10:58:00 -- 1、弹出两个值看看
msgbox(FirstRow) msgbox(EndRow)
2、我单独测试没问题,请上传具体实例测试。 |