ven. 17 février 2012, 15h39
Gregory
atoutfox.public.association
Re: Impression Fichiers
Ici, c'est bien imprime, mais word donne une erreur a la fin
Mais ce bout de code imprimera un doc ou docx
lcprinter = 'Bullzip PDF Printer'
filename = 'd:\tmp\1.docx'
= PrintWordDoc(m.filename, m.lcprinter )
function PrintWordDoc(filename, printername)
local wordObj, printerOld
=WindowsPrinter Set(m.printername, @m.printerOld)
wordObj = createObject( 'Word.Application')
=m.wordObj.Documents.Open(filename, , .t.)
#define wdDialogFilePrint 88
with m.wordObj.ActiveDocument.Application.Dialogs(wdDialogFilePrint)
.Printer = m.PrinterName
.numcopies = 1
.Execute()
endwith
declare Sleep in Win32api integer
with m.wordObj.Application
do while !empty(.BackgroundPrintingStatus)
=sleep(100)
enddo
endwith
#define wdDoNotSaveChanges 0
=m.wordObj.Quit(wdDoNotSaveChanges)
wordObj= null
=WindowsPrinter Set(m.printerOld)
endfunc
function WindowsPrinter Set(PrinterNew, PrinterOld)
local success
success = .t.
PrinterOld = WindowsPrinter Get()
if( lower(m.PrinterOld) <> lower(m.PrinterNew) )
try
if( empty(SetDefaultPrinter(m.PrinterNew)) )
assert .f.
success = .f.
endif
catch
assert .f.
success = .f.
endtry
endif
return m.success
endfunc
function WindowsPrinter Get()
return set('Printer', 2)
endfunc
function SetDefaultPrinter(pPrinterName)
local ReturnValue
try
declare Long SetDefaultPrinter In WINSPOOL.DRV ;
String pPrinterName
ReturnValue = SetDefaultPrinter (m.pPrinterName)
catch
assert .f.
ReturnValue = 0
endtry
return m.ReturnValue
endfunc
Gregory
"luckyagi" wrote in message news:jhlmoh$1lmr$1@news.niouzes.net...
Merci.
Cependant, j'ai adapté le code mais le document Word sélectionné par exemple ne s'imprime toujours pas.
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000008264