Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di cms9651
    Registrato dal
    Mar 2010
    Messaggi
    107

    Creazione dinamica di file excel

    Ciao a tutti.

    Avrei bisogno di un consiglio.

    Con questo script http://www.html.it/articoli/creazion...-file-excel-1/ genero un file excel senza problemi tramite una query in MySQL che esegui una WHERE sul campo 'soggetto'.

    Adesso però questo excel andrebbe inviato come allegato via email ad una serie di soggetti, ognuno per competenza vedrà il proprio excel compilato tramite la suddetta query.

    I soggetti principali sono A, B e C che a loro volta sono suddivisi in sotto-soggetti del tipo:

    soggetto A: sotto-soggetto A1, A2, A3 etc
    soggetto B: sotto-soggetto B1, B2, B3 etc
    soggetto C: sotto-soggetto C1, C2, C3 etc

    Devo crearmi una generazione di excel per ogni soggetto e sotto-soggetto oppure con un unico script ASP posso inviare a tutti un excel diverso di sua competenza?

    Se si può con un unico script di cosa avrei bisogno?
    Grazie

  2. #2
    se devi fare una estrazione diversa per ogni destinatario, dovrai eseguire tante SELECT...WHERE quanti sono i destinatari

    quindi

    1. leggi i destinatari
    2. prepari i criteri di estrazione
    3. esegui lo script con i criteri adatti
    4. prepari e spedisci la mail
    5. torni al punto 1. fino all'esaurimento dei destinatari


  3. #3
    Utente di HTML.it L'avatar di cms9651
    Registrato dal
    Mar 2010
    Messaggi
    107
    Grazie per il prezioso suggerimento.
    Prima di confezionare e spedire il msg email sto provando a generare per ciascun soggetto il proprio file excel, ma lo script mi crea quattro file esxcel con i dati sbagliati e solo l'ultimo con i dati corretti, perchè? Cosa sbaglio?
    Grazie
    codice:
    		
    'CONNESSIONE AL DB
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;PORT=3306;DATABASE=XXX;USER=XXX;PASSWORD=XXX;OPTION=3;" 
    
    'SUB PER LA CREAZIONE DEL FILE EXCEL
    sub listaGuasti(cn, byRef listaGuastiOutput)    
    	SQL = "SELECT * FROM "
    	SQL = SQL & " tbl_1 "
    	SQL = SQL & " WHERE "
    	SQL = SQL & " soggetto = '" & Rs1("soggetto") & "'; "
            
    	set rs = server.createObject("ADODB.Recordset")
    	rs.open SQL, cn
    		
    	if not rs.eof then
    		listaGuastiOutput = rs.getrows()
            end if  
        
       rs.Close()
       Set rs = Nothing   
    end sub	
    
       'QUERY SU SOGGETTI ASSOCIATI A EMAIL
        strSQL = "SELECT * FROM tbl_email WHERE email <> '';"
        Set Rs1 = CreateObject("ADODB.Recordset")
        Rs1.Open strSQL, cn
    
        if not Rs1.eof then 
        Do While Not Rs1.EOF     
    
        temp_excel_file = Session.SessionID & "_ " & Rs1("SOGGETTO")
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        path_modello = server.mappath("/public/modello_excel.txt")
        path_temp = server.mappath("/public/" & temp_excel_file & ".xls")
        Set a = fs.OpenTextFile(path_modello)
        file_letto = a.readall
        a.Close
    
        call listaGuasti(cn, listaGuastiOutput)
    
        tabella_guasti = ""
        guasti_totale = 0
    
    if IsArray(listaGuastiOutput) then
    	guasti_totale = Ubound(listaGuastiOutput,2)	
    	
    	For risultato = 0 to guasti_totale
    		tabella_guasti = tabella_guasti & "<tr style=vertical-align:middle;>"
    		
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(0,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(1,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(2,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(3,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(4,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(5,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(6,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(7,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(8,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(9,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(10,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(11,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(12,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(13,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(14,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(15,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(16,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & listaGuastiOutput(17,risultato) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & formatNumber(listaGuastiOutput(18,risultato),0) & "</td>"
    			tabella_guasti = tabella_guasti & "<td class=xl6430278Bordi style=text-align:center;>" & formatNumber(listaGuastiOutput(19,risultato),0) & "</td>"
    		
    		tabella_guasti = tabella_guasti & "</tr>"
    	Next
    	
    end if
    
    		Set a = fs.CreateTextFile(path_temp, True)
    		file_letto = replace(file_letto, "[guasti_totale]", guasti_totale+1)
    		file_letto = replace(file_letto, "[guasti]", tabella_guasti)
    		a.write (file_letto)
    		a.Close
    		set fs = nothing
    
    		Rs1.MoveNext()
          Loop
          End if
          
       Rs1.Close()
       Set Rs1 = Nothing       
    
    cn.Close()
    Set cn = Nothing
    
    %>

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 © 2026 vBulletin Solutions, Inc. All rights reserved.