Use ActivePrinter under OLE

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Use ActivePrinter under OLE

Postby Tranber44 on Sun Aug 16, 2015 6:15 am

Hello,

I use very often Excel under OLE to print statistical and other documents in lesser cost of development. The object PRINTER allows under APL to choose a printer other than a printer by default but it does not change the printer by default.
I tried to use the property ActivePrinter but it requires to know the virtual associated port (Ne0X:). The methods described on the forums are quite based on the same principle: make vary the value of the virtual port of Ne01: to Ne09: as long as the instruction ActivePrinter génére an anomaly but this anomaly VBA is not trapped by APL. Exist it a solution?

Best regards.

Bertrand Delassus
Tranber44
 
Posts: 34
Joined: Mon Jan 11, 2010 4:46 pm

Re: Use ActivePrinter under OLE

Postby Vince|Dyalog on Thu Aug 20, 2015 10:29 am

Hi Bertrand,

To get the Ne0x port numbers, you will need to query the registry. To do this, I would first suggest getting the ReadTree function out of the cpreg.dyalog that is part of the Dyalog 14.1 installation.

Code: Select all
'regfns'⎕NS ''
]load "C:\Program Files\Dyalog\Dyalog APL-64 14.1 Unicode\SALT\spice\cpreg.dyalog" -disperse -target=#.regfns

 prlist←regfns.ReadTree'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts'


You'll need to do some parsing/processing of the text in prlist.

e.g., for me, one of my printers has this:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\HP Color LaserJet Pro MFP M476 PCL 6 String winspool,Ne06:,15,45

So, for Excel OLEClient, this worked for me:
Code: Select all
xl.ActivePrinter←⊂'HP Color LaserJet Pro MFP M476 PCL 6 on Ne06:'


Regards,

Vince
Vince|Dyalog
 
Posts: 412
Joined: Wed Oct 01, 2008 9:39 am

Re: Use ActivePrinter under OLE

Postby PGilbert on Thu Aug 20, 2015 11:07 am

Hello Bertrand, in case this may help you:

Code: Select all
      ⎕USING←'System.Printing,WPF/System.Printing.dll'
      printServer←⎕NEW LocalPrintServer

      0=↑⍴(⌷printServer.GetPrintQueues ⍬)  ⍝ If true there is no printer installed
0
      printerList←(⌷printServer.GetPrintQueues ⍬).FullName   ⍝ All the printers installed

      defaultPrinter←printServer.DefaultPrintQueue.FullName  ⍝ name of the default printer
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: Use ActivePrinter under OLE

Postby Tranber44 on Wed Oct 26, 2016 6:43 am

Hello,
Thank you, late, for your answer and that of Vince. Now, I master perfectly my printers under Ole-Excel, but, directly under Dyalog, the use of the property PName of the object Printer is ineffective whatever is the structure of PName
('Adobe PDF,Documents\*.PDF', 'Adobe PDF,ne04:', 'Adobe PDF') although none causes error.
What should be the structure of PName to be effective?

Regards

Bertrand
Tranber44
 
Posts: 34
Joined: Mon Jan 11, 2010 4:46 pm

Re: Use ActivePrinter under OLE

Postby Vince|Dyalog on Mon Oct 31, 2016 9:39 am

Hi Bertrand,

You can get a list of printers by querying PrintList like this. The first one will be the Windows default printer.
      ⎕io⊃'.' ⎕wg 'printlist'
HP LaserJet 4200/4300 PCL6,hp4200

'p' ⎕wc 'printer' ('pname' (⎕io⊃'.' ⎕wg 'printlist'))

'p' ⎕wg 'PName'
HP LaserJet 4200/4300 PCL6,hp4200

'p' ⎕wg 'papersize'
A4


Regards,

Vince
Vince|Dyalog
 
Posts: 412
Joined: Wed Oct 01, 2008 9:39 am


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest