以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]局域网中共享打印机不能设置类 PageSetup 的 PaperSize 属性  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=112813)

--  作者:ajie5211
--  发布时间:2018/1/3 13:10:00
--  [求助]局域网中共享打印机不能设置类 PageSetup 的 PaperSize 属性

如标准,PDF打印机不报错,但局域网中的共享打印机报“不能设置类 PageSetup 的 PaperSize 属性”错误。Print Spooler服务已启动。

Dim fl As String = ProjectPath & "Reports\\冲压制令单.xls"
    With Tables("冲压生产计划追踪表")
        If .TopPosition > -1 Then \'如果选定区域包括数据行
            \'******建立主表与制令和出入的关联*********
            Relations.Add("制令关联",DataTables("冲压生产计划追踪表").DataCols("制令单号"),DataTables("冲压生产计划追踪表_Table1").DataCols("销售单号"),False,RelationPathEnum.none)
            Relations.Add("出入关联",DataTables("冲压生产计划追踪表").DataCols("制令单号"),DataTables("冲压生产计划追踪表_Table5").DataCols("制令单号"),False,RelationPathEnum.none)
            Dim ks As Integer = .TopPosition
            Dim js As Integer = .BottomPosition
            For i As Integer = ks To js
                Dim Book As New XLS.Book(ProjectPath & "Attachments\\冲压制令单.xls")
                .Select(i,0)
                \'生成条码图片
                Dim Bar As New BarCodeBuilder
                Bar.Symbology = Barpro.Symbology.Code39
                Bar.Code = .Rows(i)("制令单号")
                Bar.BarHeight = 8
                Bar.QuietZoneWidth = 2
                Bar.DisplayChecksum = False
                bar.SaveImage(ProjectPath & "Images\\zldtxm.wmf",300)
                Book.Build() \'生成细节区
                Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
                Dim prtdoc As new Printing.PrintDocument()
                prtdoc.PrinterSettings.PrinterName = GetConfigValue("_zlddyj",DefaultPrinter) \'设置打印机名称
                Sheet.MergeCell(2,9,21,1) \'合并提示列
                sheet(1,6).Value = Date.Now
                \'fl = ProjectPath & "Reports\\" & .Rows(i)("制令单号") & ".pdf"
                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 zzmcs As new List(of String) \'自动添加24x28的纸张
                \'For Each ps As System.Drawing.Printing.PaperSize In prtdoc.PrinterSettings.PaperSizes  \'生成打印机的纸张下拉列表
                    \'If zzmcs.Contains(ps.PaperName) = False Then
                        \'zzmcs.Add(ps.PaperName)
                    \'End If
                \'Next
                \'If zzmcs.Contains("klj24x28") = False Then
                    \'Dim cps As new CustomPaperSize.CustomPaperSize()
                    \'\'cps.SetPrintForm(prtdoc.PrinterSettings.PrinterName,"klj24x28", 10 * GetConfigValue("_zldzzkd", 240), 10 * GetConfigValue("_zldzzgd", 280))
                    \'cps.SetPrintForm(prtdoc.PrinterSettings.PrinterName,"klj24x28", 10 * 240, 10 * 280)
                \'End If
                With Ws.PageSetup
                    \'For Each ps As System.Drawing.Printing.PaperSize In prtdoc.PrinterSettings.PaperSizes  \'生成打印机的纸张下拉列表
                        \'\'If ps.PaperName = "klj24x28" Then
                        \'If ps.PaperName = "Letter" OrElse ps.PaperName = "信纸" Then
                            \'.PaperSize = ps.RawKind
                        \'End If
                    \'Next
                    .PaperSize = MSExcel.XlPaperSize.xlPaperLetter   \'纸张大小
                    .LeftMargin = 10 \'页面左边距
                    .RightMargin = 10\'页面右边距
                    .TopMargin = 10  \'页面顶部边距
                    .BottomMargin = 10   \'页面底部边距
                    .CenterHorizontally = True   \'页面水平居中
                    \'.CenterVertically = True \'页面垂直居中
                    .Zoom = False \'以下设置将缩印在一页内
                    .FitToPagesWide = 1  \'按照1页的宽度打印
                    .FitToPagesTall = 1  \'按照1页的高度打印
                End With
                \'App.Visible = True
                Ws.PrintOut(Preview:=False,ActivePrinter:= "" & GetConfigValue("_zlddyj",DefaultPrinter) & "")
                wb.save
                wb.close
                App.Quit               
            Next
            \'******删除建立的关联*****
            Relations.Delete("制令关联")
            Relations.Delete("出入关联")
    End With


--  作者:有点甜
--  发布时间:2018/1/3 15:43:00
--  

你把打印机设置成默认打印机了没有?要设置的。

 

只要你的值是正确的,设置这句代码没问题的,如 .PaperSize = 9

 

局域网打印机,有可能不能使用 CustomPaperSize.CustomPaperSize 添加纸张。


--  作者:ajie5211
--  发布时间:2018/1/4 8:03:00
--  
以下是引用有点甜在2018/1/3 15:43:00的发言:

你把打印机设置成默认打印机了没有?要设置的。

 

只要你的值是正确的,设置这句代码没问题的,如 .PaperSize = 9

 

局域网打印机,有可能不能使用 CustomPaperSize.CustomPaperSize 添加纸张。

因为要打不同的单子,用的打印机不同,有没有什么代码可以临时切换默认打印机的,打这个默认打印机切过来,打完后,再切回去?
--  作者:有点甜
--  发布时间:2018/1/4 9:46:00
--  
以下是引用ajie5211在2018/1/4 8:03:00的发言:
因为要打不同的单子,用的打印机不同,有没有什么代码可以临时切换默认打印机的,打这个默认打印机切过来,打完后,再切回去?

 

参考代码

 

Dim obj As object = CreateObject("WScript.Network")
obj.SetDefaultPrinter("打印机名")