Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 17
  1. #1
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305

    [OpenOffice Calc macro] recupero dati da tutti i fogli presenti

    Ho una serie di fogli + altri 2 fogli di riepilogo all'interno di un file.

    In tutti i fogli presenti (tranne i 2 riepiloghi) devo estrapolare dei dati e inserirli nella scheda di un riepilogo elencandoli a partire dalla riga 14.

    Esempio:

    Devo recuperare il contenuto della cella B7 di ogni foglio e inserirlo all'interno delle celle del foglio di riepilogo a partire dalla cella A14, quindi ad es. la cella B7 del foglio1 conterrà AAA e dovrò inserirlo in A14, poi il foglio2 conterrà FRA e dovrò inserirlo nella cella A15 e cosi via.

    Immagino di dover fare una specie di ciclo for per dirgli "estrapolami i dati di ogni foglio tranne gli ultimi 2 fogli" ma come si fa? Potete aiutarmi? grazie

  2. #2
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    ho iniziato facendo così ma non so andare avanti

    codice:
    oCalcDocument = ThisComponent
     oSheets = oCalcDocument.getSheets()
    
     For I = 0 to oSheets.Count -4
            oCalcSheet = oSheets.getByIndex(I)
        oCalcSheet.Name 
           
        Next I
    al posto del codice in grassetto dovrei dirgli: prendimi il valore della cella b7 e inseriscimela nellascheda di riespilogo a partire dalla a14...

  3. #3
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    questo è quello che ho combinato fino ad ora...
    su un foglio solo funziona ma se ho piu fogli mi da errore su dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args6())
    e mi dice sequence element is not asignable by given value... aiutatemi! devo finirlo entro oggi pomeriggio!

    codice:
    SUB DISTINTA
    
    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")
    
        
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$A$14"
    
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
          
    dim OBJSTS as object                          ' VAR. OGGETTO x INSIEME SHEETS
       dim IDSH as integer                           ' VAR. NUMERICA x CONTEGGIO SHEETS  
       dim NMSH as string                            ' VAR, PER NOME SHEET DI CICLO
       OBJSTS = thiscomponent.sheets                 ' ACQUISISCO OGGETTO INSIEME SHEETS
       for IDSH = 0 to OBJSTS.count - 5             ' CICLO SU CONTEGGIO SHEETS
          NMSH = OBJSTS.getbyindex(IDSH).name        ' SCRIVO NOME SHEET DI CICLO IN VAR.
          
          
     
          
          
          
        oCalcDocument = ThisComponent
    oSheets = oCalcDocument.getSheets()
    oSheet = oSheets(idsh)
          oCell = oSheet.getCellByPosition(1, 6)  ' b7
          msgbox "Prova contenuto b7 fogli: " & ocell.string & " " & idsh
          
      
       
       thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
     
     '------------------------------------------------------------------------
    rem ----------------------------------------------------------------------
    dim args6(0) as new com.sun.star.beans.PropertyValue
    args6(0).Name = "StringName"
    
    args6(0).Value = ocell.string
    
      dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args6())
         next IDSH                                ' CHIUDO CICLO SU ELENCO SHEETS
             
    
    rem ----------------------------------------------------------------------
    dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())                    
    END SUB

  4. #4
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    Ho pacioccato fino ad ottenere questo modo: ho ottenuto l'elenco a partire dalla riga a14 della distinta, mi fa il ciclo ma mi scrive sempre in tutte le celle il valore della cella B7 del primo foglio MENTRE NEL A15 DOVREBBE SCRIVERE IL VALORE DELLA CELLA DEL SECONDO FOGLIO E COSI VIA... AIUTOOOOOO!!! URGENTEEEE

    codice:
    SUB DISTINTA
    
    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")
     thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
        
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$A$14"
    
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
          
    dim OBJSTS as object                          ' VAR. OGGETTO x INSIEME SHEETS
       dim IDSH as integer                           ' VAR. NUMERICA x CONTEGGIO SHEETS  
       dim NMSH as string                            ' VAR, PER NOME SHEET DI CICLO
       OBJSTS = thiscomponent.sheets    
        dim args6(400) as new com.sun.star.beans.PropertyValue   
               
       for IDSH = 0 to OBJSTS.count - 5             ' CICLO SU CONTEGGIO SHEETS
          NMSH = OBJSTS.getbyindex(IDSH).name        ' SCRIVO NOME SHEET DI CICLO IN VAR.
          
          
     
          
          
          
        oCalcDocument = ThisComponent
    oSheets = oCalcDocument.getSheets()
    oSheet = oSheets(idsh)
          oCell = oSheet.getCellByPosition(1, 6)  ' b7
        '  msgbox "Prova contenuto b7 fogli: " & ocell.string & " " & idsh
          
      
       
       thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
     
     '------------------------------------------------------------------------
    rem ----------------------------------------------------------------------
    'dim args6(6) as new com.sun.star.beans.PropertyValue
    args6(idsh).Name = "StringName"
    'args6(0).Value = "='" & nomefoglio &"'.j16" ' DA CHANCE IN BASE A ULTIMA DATA - VEDI FORUM ------------------------------------------------------
    args6(idsh).Value = ocell.string
    msgbox idsh
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args6())
    dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array()) 
    
    idsh=idsh +1
         next IDSH                                ' CHIUDO CICLO SU ELENCO SHEETS
             
    
    rem ----------------------------------------------------------------------
    
                         
    END SUB

  5. #5
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    Ho pacioccato fino ad ottenere questo modo: ho ottenuto l'elenco a partire dalla riga a14 della distinta, mi fa il ciclo ma mi scrive sempre in tutte le celle il valore della cella B7 del primo foglio MENTRE NEL A15 DOVREBBE SCRIVERE IL VALORE DELLA CELLA DEL SECONDO FOGLIO E COSI VIA... AIUTOOOOOO!!! URGENTEEEE

    codice:
    SUB DISTINTA
    
    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")
     thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
        
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$A$14"
    
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
          
    dim OBJSTS as object                          ' VAR. OGGETTO x INSIEME SHEETS
       dim IDSH as integer                           ' VAR. NUMERICA x CONTEGGIO SHEETS  
       dim NMSH as string                            ' VAR, PER NOME SHEET DI CICLO
       OBJSTS = thiscomponent.sheets    
        dim args6(400) as new com.sun.star.beans.PropertyValue   
               
       for IDSH = 0 to OBJSTS.count - 5             ' CICLO SU CONTEGGIO SHEETS
          NMSH = OBJSTS.getbyindex(IDSH).name        ' SCRIVO NOME SHEET DI CICLO IN VAR.
          
          
     
          
          
          
        oCalcDocument = ThisComponent
    oSheets = oCalcDocument.getSheets()
    oSheet = oSheets(idsh)
          oCell = oSheet.getCellByPosition(1, 6)  ' b7
        '  msgbox "Prova contenuto b7 fogli: " & ocell.string & " " & idsh
          
      
       
       thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
     
     '------------------------------------------------------------------------
    rem ----------------------------------------------------------------------
    'dim args6(6) as new com.sun.star.beans.PropertyValue
    args6(idsh).Name = "StringName"
    'args6(0).Value = "='" & nomefoglio &"'.j16" ' DA CHANCE IN BASE A ULTIMA DATA - VEDI FORUM ------------------------------------------------------
    args6(idsh).Value = ocell.string
    msgbox idsh
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args6())
    dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array()) 
    
    idsh=idsh +1
         next IDSH                                ' CHIUDO CICLO SU ELENCO SHEETS
             
    
    rem ----------------------------------------------------------------------
    
                         
    END SUB

  6. #6
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    Originariamente inviato da luisa227
    Ho pacioccato fino ad ottenere questo modo: ho ottenuto l'elenco a partire dalla riga a14 della distinta, mi fa il ciclo ma mi scrive sempre in tutte le celle il valore della cella B7 del primo foglio MENTRE NEL A15 DOVREBBE SCRIVERE IL VALORE DELLA CELLA DEL SECONDO FOGLIO E COSI VIA... AIUTOOOOOO!!! URGENTEEEE

    codice:
    SUB DISTINTA
    
    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")
     thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
        
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$A$14"
    
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
          
    dim OBJSTS as object                          ' VAR. OGGETTO x INSIEME SHEETS
       dim IDSH as integer                           ' VAR. NUMERICA x CONTEGGIO SHEETS  
       dim NMSH as string                            ' VAR, PER NOME SHEET DI CICLO
       OBJSTS = thiscomponent.sheets    
        dim args6(400) as new com.sun.star.beans.PropertyValue   
               
       for IDSH = 0 to OBJSTS.count - 5             ' CICLO SU CONTEGGIO SHEETS
          NMSH = OBJSTS.getbyindex(IDSH).name        ' SCRIVO NOME SHEET DI CICLO IN VAR.
          
          
     
          
          
          
        oCalcDocument = ThisComponent
    oSheets = oCalcDocument.getSheets()
    oSheet = oSheets(idsh)
          oCell = oSheet.getCellByPosition(1, 6)  ' b7
        '  msgbox "Prova contenuto b7 fogli: " & ocell.string & " " & idsh
          
      
       
       thiscomponent.currentcontroller.activesheet = _
          thiscomponent.sheets.getbyname("DISTINTA")   
     
     '------------------------------------------------------------------------
    rem ----------------------------------------------------------------------
    'dim args6(6) as new com.sun.star.beans.PropertyValue
    args6(idsh).Name = "StringName"
    'args6(0).Value = "='" & nomefoglio &"'.j16" ' DA CHANCE IN BASE A ULTIMA DATA - VEDI FORUM ------------------------------------------------------
    args6(idsh).Value = ocell.string
    msgbox idsh
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args6())
    dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array()) 
    
    idsh=idsh +1
         next IDSH                                ' CHIUDO CICLO SU ELENCO SHEETS
             
    
    rem ----------------------------------------------------------------------
    
                         
    END SUB
    nessun esperto, sono disposta a pagare, ormai sono settimane che ci sto sù :/

  7. #7
    domanda: ma i nomi dei fogli dai quali estrai i dati li conosci?

    Sono in numero fisso o in numero variabile?

  8. #8
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    Originariamente inviato da raven74
    domanda: ma i nomi dei fogli dai quali estrai i dati li conosci?

    Sono in numero fisso o in numero variabile?
    no, non conosco i nomi e sono in numero variabile, infatti faccio nel codice -5 perchè ho 5 fogli "fissi" nelle ultime posizioni.

  9. #9
    mai programmato in openoffice basic.

    Ad ogni modo conosci almeno i nomi dei fogli con le distinte? Io ho ipotizzato che si chiamassero 'distinta' 'pippo' e 'pluto'

    io quindi farei così

    Codice PHP:
    Function Prova
    Doc 
    Thiscomponent
    Sheet 
    Doc.Sheets
    row 
    14
    distinta 
    Doc.sheets.getbyname("distinta")   
    for 
    each sheet in Doc.Sheets
        
    if(sheet.name <> "distinta" and sheet.name <> "pippo"  and sheet.name <> "pluto"Then
            valore 
    =  sheet.getCellByPosition(16).String
            distinta
    .getCellByPosition(0row).String valore
            row 
    row 1
        
    endif
    next sheet
    NomeFoglio
    =Sheet.name
    End 
    function 

  10. #10
    Utente di HTML.it L'avatar di luisa227
    Registrato dal
    Mar 2002
    Messaggi
    2,305
    perfetto, ho aggiustato un poco e funziona! Grazie mille!

    Ora però ho un altro problemone che mi hanno richiesto solo ora:
    devo pescare non tutti i fogli, ma solo quelli corrispondenti all'anno di riferimento scelto.
    La data di riferimento è contenuta in ogni foglio nell'intervallo di celle da j7 a j16 da cui io ovviamente devo pescare il MAX x ottenere la data maggiore di tutte. Quindi se mi riferisco al 2011 e in un foglio la data maggiore è ad es. 11/11/2011 lo devo pescare altrimenti no.
    Come implemento il tutto? Ho già fatto l'inputbox e poi credo che devo fare un if per vedere se il max dell'intervallo delle celle di ogni foglio corrisponde al valore del inputbox. Ma come? grazie

    codice:
    SUB DISTINTA2 ' 
    Doc = Thiscomponent 
    Sheet = Doc.Sheets 
    row = 13 
     distinta1 = Doc.sheets.getbyname("DISTINTA") 
    
    sText = InputBox ("Anno di riferimento: ","Scelta anno di riferimento")
    for each sheet in Doc.Sheets 
        if(sheet.name <> "DISTINTA" and sheet.name <> "SCHEDA SINTETICA DI PARTITA"  and sheet.name <> "RIPARTO FRUTTI") Then 
        'if max di j7-j16 =anno
        'datadiriferimento= max(
            valore =  sheet.getCellByPosition(1, 6).String ' numero partita
            VALORE2=  sheet.getCellByPosition(2, 6).value ' numero capi
               VALORE3=  sheet.getCellByPosition(5, 6).VALUE ' peso iniziale
               
    
               VALORE4=  sheet.getCellByPosition(8, 39).value
                VALORE5=  sheet.getCellByPosition(14, 17).value
            distinta1 = Doc.sheets.getbyname("DISTINTA") 
         
        
            distinta1.getCellByPosition(0, row).String = valore
            distinta1.getCellByPosition(1, row).VALUE = valore2 
            distinta1.getCellByPosition(3, row).VALUE =VALORE3
            
              distinta1.getCellByPosition(7, row).value =VALORE4
        distinta1.getCellByPosition(4, row).value =VALORE5
       
           
            row = row + 1 
        endif 
    next sheet 
    NomeFoglio=Sheet.name 
    End SUB

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.