Use ActivePrinter under OLE
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 !
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 !
5 posts
• Page 1 of 1
Use ActivePrinter under OLE
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
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
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.
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:
Regards,
Vince
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: 413
- Joined: Wed Oct 01, 2008 9:39 am
Re: Use ActivePrinter under OLE
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
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: Use ActivePrinter under OLE
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
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
Hi Bertrand,
You can get a list of printers by querying PrintList like this. The first one will be the Windows default printer.
Regards,
Vince
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: 413
- Joined: Wed Oct 01, 2008 9:39 am
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group