[Risolto] Stampa diretta

Creare una macro - Scrivere uno script - Usare le API
Rispondi
mario-T
Messaggi: 38
Iscritto il: venerdì 7 marzo 2014, 12:48

[Risolto] Stampa diretta

Messaggio da mario-T »

Ciao, espongo prima a cosa serve la macro. Funziona così, dal foglio1 passo al foglio2 dove stampo la prima ed unica pagina che c'è, ritorno al foglio1 cancello i dati che ci sono nella prima riga sposto in alto tutti quelli che ci sono sotto e la macro finisce in attesa di un nuovo via. So che non è una soluzione molto elegante per stampare delle schede in sequenza ma è la più semplice che mi è venuta in mente. Ora il problema ERA che la macro, dopo essere stata avviata aspettava che io cliccassi invio per far partire la stampa.... Ho trovato in rete una soluzione che risolve questo problema che è quella qui sotto

Codice: Seleziona tutto

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Nr"
args1(0).Value = 3

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())


args1(0).Name = "Nr"
args1(0).Value = 3

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

rem ----------------------------------------------------------------------
dim argsXY1(0) as new com.sun.star.beans.PropertyValue
dim argsXY2(2) as new com.sun.star.beans.PropertyValue



      argsXY1(0).Name = "Nr"

         argsXY2(0).Name = "Copies"
         argsXY2(0).Value = 1
         argsXY2(1).Name = "Selection"
         argsXY2(1).Value = true
         argsXY2(2).Name = "Collate"
         argsXY2(2).Value = false
         

for i=1 to 1

   argsXY1(0).Value = i

   dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 3, argsXY1())

   rem ----------------------------------------------------------------------
      dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
         dispatcher.executeDispatch(document, ".uno:Print", "", 0, argsXY2())
   
next i

rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Nr"
args3(0).Value = 1

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args4())

rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "By"
args5(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args5())

rem ----------------------------------------------------------------------
dim args6(0) as new com.sun.star.beans.PropertyValue
args6(0).Name = "By"
args6(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args6())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "By"
args7(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args7())

rem ----------------------------------------------------------------------
dim args8(0) as new com.sun.star.beans.PropertyValue
args8(0).Name = "By"
args8(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args8())

rem ----------------------------------------------------------------------
dim args9(0) as new com.sun.star.beans.PropertyValue
args9(0).Name = "By"
args9(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args9())

rem ----------------------------------------------------------------------
dim args10(0) as new com.sun.star.beans.PropertyValue
args10(0).Name = "By"
args10(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args10())

rem ----------------------------------------------------------------------
dim args11(0) as new com.sun.star.beans.PropertyValue
args11(0).Name = "By"
args11(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args11())

rem ----------------------------------------------------------------------
dim args12(0) as new com.sun.star.beans.PropertyValue
args12(0).Name = "By"
args12(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args12())

rem ----------------------------------------------------------------------
dim args13(0) as new com.sun.star.beans.PropertyValue
args13(0).Name = "By"
args13(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args13())

rem ----------------------------------------------------------------------
dim args14(0) as new com.sun.star.beans.PropertyValue
args14(0).Name = "By"
args14(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args14())

rem ----------------------------------------------------------------------
dim args15(0) as new com.sun.star.beans.PropertyValue
args15(0).Name = "By"
args15(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args15())

rem ----------------------------------------------------------------------
dim args16(0) as new com.sun.star.beans.PropertyValue
args16(0).Name = "By"
args16(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args16())

rem ----------------------------------------------------------------------
dim args17(0) as new com.sun.star.beans.PropertyValue
args17(0).Name = "By"
args17(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args17())

rem ----------------------------------------------------------------------
dim args18(0) as new com.sun.star.beans.PropertyValue
args18(0).Name = "By"
args18(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args18())

rem ----------------------------------------------------------------------
dim args19(0) as new com.sun.star.beans.PropertyValue
args19(0).Name = "By"
args19(0).Value = 1

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args19())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------
dim args21(0) as new com.sun.star.beans.PropertyValue
args21(0).Name = "Sel"
args21(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStartOfRow", "", 0, args21())

rem ----------------------------------------------------------------------
dim args22(1) as new com.sun.star.beans.PropertyValue
args22(0).Name = "By"
args22(0).Value = 1
args22(1).Name = "Sel"
args22(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args22())

rem ----------------------------------------------------------------------
dim args23(1) as new com.sun.star.beans.PropertyValue
args23(0).Name = "By"
args23(0).Value = 1
args23(1).Name = "Sel"
args23(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args23())

rem ----------------------------------------------------------------------
dim args24(1) as new com.sun.star.beans.PropertyValue
args24(0).Name = "By"
args24(0).Value = 1
args24(1).Name = "Sel"
args24(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args24())

rem ----------------------------------------------------------------------
dim args25(0) as new com.sun.star.beans.PropertyValue
args25(0).Name = "Sel"
args25(0).Value = true

dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args25())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------
dim args28(0) as new com.sun.star.beans.PropertyValue
args28(0).Name = "Sel"
args28(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args28())

rem ----------------------------------------------------------------------
dim args29(1) as new com.sun.star.beans.PropertyValue
args29(0).Name = "By"
args29(0).Value = 1
args29(1).Name = "Sel"
args29(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args29())

rem ----------------------------------------------------------------------
dim args30(1) as new com.sun.star.beans.PropertyValue
args30(0).Name = "By"
args30(0).Value = 1
args30(1).Name = "Sel"
args30(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args30())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args32(1) as new com.sun.star.beans.PropertyValue
args32(0).Name = "By"
args32(0).Value = 1
args32(1).Name = "Sel"
args32(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args32())

rem ----------------------------------------------------------------------
dim args33(1) as new com.sun.star.beans.PropertyValue
args33(0).Name = "By"
args33(0).Value = 1
args33(1).Name = "Sel"
args33(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args33())


end sub
La parte posticcia è quella che va da: dim args1(0) as new com.sun.star.beans.PropertyValue sino al next i
Il ciclo for next c' era e si ripeteva per tre volte non so perchè, io l'ho messo a uno e l'ho lasciato.... Ora mi sono detto perchè non facciamo un bel ciclino for next in modo che posso lanciare tutte le stampe che voglio? Così ho modificato il codice nella maniera qui sotto

Codice: Seleziona tutto

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
dim argsXY1(0) as new com.sun.star.beans.PropertyValue
dim argsXY2(2) as new com.sun.star.beans.PropertyValue
dim args3(0) as new com.sun.star.beans.PropertyValue
dim args4(0) as new com.sun.star.beans.PropertyValue
dim args21(0) as new com.sun.star.beans.PropertyValue
dim args22(1) as new com.sun.star.beans.PropertyValue
dim args23(1) as new com.sun.star.beans.PropertyValue
dim args24(1) as new com.sun.star.beans.PropertyValue
dim args25(0) as new com.sun.star.beans.PropertyValue
dim args28(0) as new com.sun.star.beans.PropertyValue
dim args29(1) as new com.sun.star.beans.PropertyValue
dim args30(1) as new com.sun.star.beans.PropertyValue
dim args32(1) as new com.sun.star.beans.PropertyValue
dim args33(1) as new com.sun.star.beans.PropertyValue


for z = 1 to 10

args1(0).Name = "Nr"
args1(0).Value = 3

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())


args1(0).Name = "Nr"
args1(0).Value = 3

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

rem ----------------------------------------------------------------------





      argsXY1(0).Name = "Nr"

         argsXY2(0).Name = "Copies"
         argsXY2(0).Value = 1
         argsXY2(1).Name = "Selection"
         argsXY2(1).Value = true
         argsXY2(2).Name = "Collate"
         argsXY2(2).Value = false
         

for i=1 to 1

   argsXY1(0).Value = i

   dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 3, argsXY1())

   rem ----------------------------------------------------------------------
      dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
         dispatcher.executeDispatch(document, ".uno:Print", "", 0, argsXY2())
   
next i



rem ----------------------------------------------------------------------

args3(0).Name = "Nr"
args3(0).Value = 1

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args3())

rem ----------------------------------------------------------------------

args4(0).Name = "By"
args4(0).Value = 16

dispatcher.executeDispatch(document, ".uno:GoRightSel", "", 0, args4())



rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------

args21(0).Name = "Sel"
args21(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStartOfRow", "", 0, args21())

rem ----------------------------------------------------------------------

args22(0).Name = "By"
args22(0).Value = 1
args22(1).Name = "Sel"
args22(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args22())

rem ----------------------------------------------------------------------

args23(0).Name = "By"
args23(0).Value = 1
args23(1).Name = "Sel"
args23(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args23())

rem ----------------------------------------------------------------------

args24(0).Name = "By"
args24(0).Value = 1
args24(1).Name = "Sel"
args24(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args24())

rem ----------------------------------------------------------------------

args25(0).Name = "Sel"
args25(0).Value = true

dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args25())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------

args28(0).Name = "Sel"
args28(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args28())

rem ----------------------------------------------------------------------

args29(0).Name = "By"
args29(0).Value = 1
args29(1).Name = "Sel"
args29(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args29())

rem ----------------------------------------------------------------------

args30(0).Name = "By"
args30(0).Value = 1
args30(1).Name = "Sel"
args30(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args30())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------

args32(0).Name = "By"
args32(0).Value = 1
args32(1).Name = "Sel"
args32(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args32())

rem ----------------------------------------------------------------------

args33(0).Name = "By"
args33(0).Value = 1
args33(1).Name = "Sel"
args33(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args33())

next z
end sub
Ma purtroppo non funziona, o meglio stampa una scheda ok ed una vuota....
A questo punto le domande, in primis quale è il codice corretto per inviare una pagina alla stampa senza bisogno di dare invio? Secondo cosa c'è che non va nella seconda macro che non fa stampare correttamente?
So che il messaggio è lungo, e vi ringrazio per essere arrivati in fondo, ma ho cercato di essere più chiaro possibile.
GRAZIE
Ultima modifica di charlie il domenica 25 settembre 2016, 14:15, modificato 3 volte in totale.
Motivazione: Inserita spunta verde
LibreOffice 7.3.7.2 su LinuxMint 21.3
Avatar utente
Mizio1961
Volontario
Volontario
Messaggi: 841
Iscritto il: mercoledì 5 ottobre 2011, 22:55
Località: Roma

Re: Stampa diretta

Messaggio da Mizio1961 »

Ciao, io uso stampare con una macro tipo la seguente:

Codice: Seleziona tutto

private sub F4_PrntDoc(oDoc)                     ' STAMPA FILE CORRENTE
   dim oPrntr as object
   dim oPrint(0) as new com.sun.star.beans.PropertyValue
   '---------------------------------------------'
   oPrntr = oDoc.Printer                         ' ACQ. LA STAMPANTE CORRENTE 
   oPrntr(0).value = "TOSHIBAUniPrinterTCP"      ' IMPOSTA PROPIETA' STAMPANTE TOSHIBAUniPrinterTCP
   oPrint(0).Name  = "CopyCount"                 ' IMPOSTA COPIE DA STAMPARE
   oPrint(0).Value = 1                           ' AL VALORE 1
   oDoc.Printer    = oPrntr()                    ' ASSEGNA LE IMPOSTAZIONI STAMPANTE
   oDoc.Print(oPrint())                          ' STAMPA
   '---------------------------------------------' "HP LaserJet 6L"  
End Sub                                          ' FINE
I commenti indicano ciò che succede a ogni riga, per cui ti occorre solo dargli l'oggetto documento da stampare e cambiare il nome della stampante con quello della tua.
Se ti fosse difficile realizzare il tutto, puoi allegare un esempio del tuo file senza dati 'sensibili' e ti aggancio la macro. ;-)
Saluti By Mizio
OpenOffice Windows - Libre su Ubuntu Desktop e Notebook WiFi
Per cortesia, inserisci [Risolto] nel Titolo iniziale se il tuo problema è stato risolto. ;-)
mario-T
Messaggi: 38
Iscritto il: venerdì 7 marzo 2014, 12:48

Re: Stampa diretta

Messaggio da mario-T »

Ciao
ho provato con una nuova routine di stampa, ma il risultato è lo stesso, se inserisco un ciclo for next, pur togliendo tutti i dim dall' interno del ciclo, mi escono alternate schede vuote e schede piene. Senza ciclo funziona tutto.
Boh, allego il file di prova, prima di avviare la macro bisogna essere nel foglio2 nella cella A1.
Aspetto fiducioso.... :mrgreen: :mrgreen: :mrgreen:
Grazie
Allegati
SCHEDAtest1.ods
(39.48 KiB) Scaricato 192 volte
LibreOffice 7.3.7.2 su LinuxMint 21.3
mario-T
Messaggi: 38
Iscritto il: venerdì 7 marzo 2014, 12:48

Re: Stampa diretta

Messaggio da mario-T »

Ciao
trovato soluzione, in pratica c'è da inserire un wait dopo la stampa, non so perchè, ma ora funziona il codice è:

Codice: Seleziona tutto

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
dim args1(0) as new com.sun.star.beans.PropertyValue
dim args3(0) as new com.sun.star.beans.PropertyValue
dim args4(0) as new com.sun.star.beans.PropertyValue
dim args6(1) as new com.sun.star.beans.PropertyValue
dim args7(0) as new com.sun.star.beans.PropertyValue
dim args10(0) as new com.sun.star.beans.PropertyValue
dim args12(1) as new com.sun.star.beans.PropertyValue
dim args13(1) as new com.sun.star.beans.PropertyValue
    DIM oPropertyValue(0) AS New com.sun.star.beans.PropertyValue
    Dim oPrinterSettings(0) As New com.sun.star.beans.PropertyValue
    DIM oDoc As Object
DIM oSettings As Object
 oDoc = ThisComponent



rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")


for i = 1 to 4



rem ----------------------------------------------------------------------

args1(0).Name = "Nr"
args1(0).Value = 3

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())







  rem oDoc = ThisComponent

    ' *** This works to set which printer I will send output to, in this case, the Fax printer server ***
    ' ***  I do not yet know how to pass arguments to the Fax server: number to call, cover page info, etc ***
    oPrinterSettings(0).Name = "Name"
    oPrinterSettings(0).Value = "Fax"
    oDoc.setPrinter(oPrinterSettings)

    ' *** I do not think oSettings is needed for basic printing.  It looks like it pertains to the document ****
    'oSettings = oDoc.createInstance("com.sun.star.text.DocumentSettings")
    '   oSettings.PrintPageBackground = False

    REM Set some print options
    oPropertyValue(0).Name = "CopyCount"
    oPropertyValue(0).Value = 1
    oDoc.Print(oPropertyValue())
    rem End Sub



wait 30000





















rem ----------------------------------------------------------------------

args3(0).Name = "Nr"
args3(0).Value = 1

dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args3())

rem ----------------------------------------------------------------------

args4(0).Name = "Sel"
args4(0).Value = true

dispatcher.executeDispatch(document, ".uno:GoToEndOfRow", "", 0, args4())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------

args6(0).Name = "By"
args6(0).Value = 1
args6(1).Name = "Sel"
args6(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args6())

rem ----------------------------------------------------------------------

args7(0).Name = "Sel"
args7(0).Value = true

dispatcher.executeDispatch(document, ".uno:GoToEndOfData", "", 0, args7())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

rem ----------------------------------------------------------------------

args10(0).Name = "Sel"
args10(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args10())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------

args12(0).Name = "By"
args12(0).Value = 1
args12(1).Name = "Sel"
args12(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args12())

rem ----------------------------------------------------------------------

args13(0).Name = "By"
args13(0).Value = 1
args13(1).Name = "Sel"
args13(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args13())

next i
end sub
Ciao
LibreOffice 7.3.7.2 su LinuxMint 21.3
Avatar utente
charlie
Site Admin
Site Admin
Messaggi: 8945
Iscritto il: mercoledì 19 dicembre 2012, 10:50
Contatta:

Re: Stampa diretta [RISOLTO]

Messaggio da charlie »

charlie
macOS 14.6.1 Sonoma: Open Office 4.1.15 - LibreOffice 7.5.7.2
http://www.charlieopenoffice.altervista.org
mario-T
Messaggi: 38
Iscritto il: venerdì 7 marzo 2014, 12:48

Re: Stampa diretta [RISOLTO]

Messaggio da mario-T »

charlie ha scritto:viewtopic.php?f=1&t=5661
:super:
LibreOffice 7.3.7.2 su LinuxMint 21.3
Rispondi