Ci ho messo una pezza... anche se mi sembra strano che sia necessario distruggere tutte le aree di stampa esistenti sul docucumento...

Questo è il codice aggiornato... probabilmente è da ripulire... ma sono stanco e così già funziona... Adesso possiamo avere diverse sheet nella medesima workbook, ciascuna con un diverso range pre-definito da "stampare" in pdf...

'notte

bart

REM INIZIO CODICE
Sub esporta_fattura_in_pdf_
' si rende necessario cancellare prima tutte le aree
' di stampa esistenti sula Worksheet
' Quindi, dopo aver passato questa macro, l'unica area di stampa
' sarà solo quella definita nel nostro range qui sotto...
  Dim selArea(0) as new com.sun.star.table.CellRangeAddress
  Dim sCartella As String
  Dim oName as string
  Dim oMycell as object
  Dim oDoc as object
  Dim oCell as object
  Dim oNumero as string
  Dim oSheet as object
  Dim oSheets
  Dim i%
  oDoc = Thiscomponent
  oSheets = ThisComponent.Sheets ' enumeta le sheets
  For i = 0 to oSheets.getCount() - 1
    oSheet = ThisComponent.Sheets.getByIndex(i)
    oSheet.setPrintareas(array()) ' e su caduna cancella
  Next                       ' le aree di stampa
  oNomeSheet = odoc.currentcontroller.activesheet.name
  selArea(0).StartColumn = nStC
  selArea(0).StartRow = nStR
  selArea(0).EndColumn = nEndC
  selArea(0).EndRow = nEndR
  oSheet=ThisComponent.Sheets.getByName(oNomeSheet)
  oSheet.setPrintareas(selArea())

        Dim myProps(1) as New com.sun.star.beans.PropertyValue
        'il valore di questo array va impostato a 1
        ' non capisco ma mi adeguo
        oSheet = ThisComponent.CurrentController.ActiveSheet
        oMycell = oSheet.getCellRangeByName("$j$5")
        oNumero = oMycell.string
        ' print oNumero 'adesso hai una parte del nome
        ' potrebbe essere il numero della fattura
        ' allo stesso modo puoi prelevare il nome del cliente
        ' adesso aggiungamo un po' di roba
        oAnno = "2006"
        oRange = oSheet.getCellRangeByName("A1:H51").getRangeAddress()
        
ThisComponent.CurrentController.getActiveSheet().setPrintAreas(Array(oRange))
        'queste 2 linee precedenti servono aselezionare un' area del foglio 
attivo
        'in questo caso A1 H51

        sCartella = Folder()
        print sCartella
'Questa variabile chiama la funzione Folder()
'la quale apre una finestra nella quale puoi
'scegliere la cartella dove vuoi salvare.
'La riga "sUrl= "file:/// ...." può essere modificata
'così
        sUrl= sCartella+ "/" + "Fattura_" +oNumero + "-" + oAnno + ".pdf"
' oppure come si preferisce...
        Print sUrl   'adesso hai anche la path corrente come prima              
proposta
        myProps(1).Name = "Selection"
        myProps(1).Value = true
'queste due linee per salvare solo la parte selezionata
        myProps(0).Name="FilterName"
        myProps(0).Value = "Calc_pdf_Export"
        thisComponent.storetoUrl(sUrl,myProps())
End Sub


Function Folder()
        Dim oCartella   as Object
        Dim iAccetta    as Integer
        oCartella = CreateUnoService("com.sun.star.ui.dialogs.FolderPicker")
        iAccetta = oCartella.Execute()
        If iAccetta = 1 Then Folder() = oCartella.GetDirectory()
End Function

REM INIZIO CODICE

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Rispondere a