[Risolto] esportazione pdf solo selezione

Discussioni sull'applicazione per i fogli di calcolo
Rispondi
milus
Messaggi: 19
Iscritto il: mercoledì 5 maggio 2010, 13:09

[Risolto] esportazione pdf solo selezione

Messaggio da milus »

Salve, fino a non molto tempo fa utilizzavo una macro che avevo trovato e riadattato da internet per esportare in pdf una precisa area di un foglio di calc.
La macro era questa:

Codice: Seleziona tutto

REM  *****  BASIC  *****

sub test

  'prepara il range da esportare:
  oRng = ThisComponent.Sheets.relazione.getCellRangeByName("A1:AA198")

  'configurazione del filtro (viene usata più sotto)
  Dim mFilterData(0) As New com.sun.star.beans.PropertyValue
  mFilterData(0).Name = "Selection"
  mFilterData(0).Value = oRng

  'parametri di esportazione
  Dim mStoreOpts(2) As New com.sun.star.beans.PropertyValue
  mStoreOpts(0).Name = "Overwrite"
  mStoreOpts(0).Value = True
  mStoreOpts(1).Name = "FilterName"
  mStoreOpts(1).Value = "calc_pdf_Export"
  mStoreOpts(2).Name = "FilterData"
  mStoreOpts(2).Value = mFilterData()


  sUrl = "file:///home/azazel/solar/clienti/"& ThisComponent.Sheets.Progetto.getCellRangeByName("E4").String &"/" & ThisComponent.Sheets.Progetto.getCellRangeByName("E4").String & "_RelazioneTecnica.pdf"
  ThisComponent.storeToURL(sURL, mStoreOpts())

end sub
dopo un po' di tempo che non la usavo ho notato che adesso non funziona più,forse complice il passaggio a libreoffice e a qualche aggiornamento.
Ho provato allora a registrare una macro, selezionando la parte del foglio interessata,e facendo esporta pdf(selezione).Il risultato è quello voluto ma la macro creata che posto di seguito, non funziona, infatti mi stampa in pdf tutti i fogli :

Codice: Seleziona tutto

REM  *****  BASIC  *****

Sub Main

End Sub






sub relazione
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 = "ToPoint"
args1(0).Value = "$A$1:$AA$197"

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

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

dim args2(3) as new com.sun.star.beans.PropertyValue
args2(0).Name = "URL"
args2(0).Value = "file:///dati/solar/programmi_e_fogli/dimensionamento_prova.pdf"
args2(1).Name = "FilterName"
args2(1).Value = "calc_pdf_Export"
args2(2).Name = "FilterData"
args2(2).Value = Array(Array("UseLosslessCompression",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",0,95,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableTextAccessForAccessibilityTools",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarksToPDFDestination",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Selection",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))
args2(3).Name = "SelectionOnly"
args2(3).Value = false

dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args2())


end sub
mi chiedevo come mai questo comportamento e come potrei intervenire per definire esattamente la parte da stampare
Ultima modifica di milus il mercoledì 11 gennaio 2012, 15:21, modificato 1 volta in totale.
OOo 3.2.0 os:Archlinux
Avatar utente
lucky63
Volontario assiduo
Volontario assiduo
Messaggi: 2992
Iscritto il: martedì 18 maggio 2010, 17:01

Re: esportazione pdf solo selezione

Messaggio da lucky63 »

milus ha scritto:come potrei intervenire per definire esattamente la parte da stampare
Dopo aver attivato registratore macro
Da Menu - Formato - Area di stampa - Modifica
In corrispondenza della riga Area Stampa, sulla destra, clicca su pulsante zoom, finestra si rimpicciolisce, seleziona la sola area che vorresti stampare e quindi clicca nuovamente sul pulsante zoom per tornare finestra precedente. Notare indicazioni che riportano ... area definita dall'utente ... e l'area selezionata in precedenza .... confermare con ok
Passare ora alla finestra di esportazione PDF e lasciare selezionato la voce stampa TUTTO - confermare con OK - Impostare nome standard di salvataggio del file ed eventuale percorso confermare con OK.
Terminata esportazione ripristinare area stampa a tutto il foglio da Menu - Formato - Area Stampa - Modifica - nella casella che riporta la voce "Definita dall'utente" selezionare invece la voce "Intero foglio" e confermare con OK.
Terminare la registrazione macro associandola come da preferenza ....

Ecco quella così fatta, provata e riprovata funziona correttamente:

Codice: Seleziona tutto

sub EsportaSelezionePDF
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 ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:EditPrintArea", "", 0, Array())

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "PrintArea"
args2(0).Value = "$C$3:$E$5"          '-----Rem QUESTA E' L'AREA DI ESPORTAZIONE DI CUI AL TEST FATTO -----
args2(1).Name = "PrintRepeatRow"
args2(1).Value = ""
args2(2).Name = "PrintRepeatCol"
args2(2).Value = ""

dispatcher.executeDispatch(document, ".uno:ChangePrintArea", "", 0, args2())

rem ----------------------------------------------------------------------
dim args3(2) as new com.sun.star.beans.PropertyValue
args3(0).Name = "URL"
args3(0).Value = "file:///PERCORSOSALVATAGGIO/NOMEFILE.PDF"      '-----  QUI INDICARE IL PERCORSO / NomeFIle.PDF di salvataggio
args3(1).Name = "FilterName"
args3(1).Value = "calc_pdf_Export"
args3(2).Name = "FilterData"
args3(2).Value = Array(Array("UseLosslessCompression",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTaggedPDF",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EmbedStandardFonts",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FormsType",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("AllowDuplicateFieldNames",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableTextAccessForAccessibilityTools",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarksToPDFDestination",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPasswords",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PreparedPermissionPassword",0,Array(),com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))

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

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

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

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


end sub
Notare le righe dove apportare le variazioni del caso:

args2(0).Value = "$C$3:$E$5" <-----Rem QUESTA E' L'AREA DI ESPORTAZIONE DI CUI AL TEST FATTO -----
args3(0).Value = "file:///PERCORSOSALVATAGGIO/NOMEFILE.PDF" <----- QUI INDICARE IL PERCORSO / NomeFIle.PDF di salvataggio

-----------------------

In alternativa alla procedura sopra descritta si potrebbe creare nello stesso file un ulteriore foglio di lavoro nel quale intercettare la sola area interessata all'esportazione e poi registrare macro esportare in pdf quest'ultimo foglio senza effettuare definizione area stampa...
..
.
milus
Messaggi: 19
Iscritto il: mercoledì 5 maggio 2010, 13:09

Re: esportazione pdf solo selezione

Messaggio da milus »

Grazie mille Lucky..adesso è perfetto.
OOo 3.2.0 os:Archlinux
Avatar utente
lucky63
Volontario assiduo
Volontario assiduo
Messaggi: 2992
Iscritto il: martedì 18 maggio 2010, 17:01

Re: esportazione pdf solo selezione

Messaggio da lucky63 »

milus ha scritto:Grazie mille Lucky..adesso è perfetto.
Di nulla ... e a buon rendere ...
..
.
Rispondi