🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: free.it.visual-basic
Article #3023

Re: Spedire un recordset via mail in formato Excel

#3023
From: Sergio
Date: Tue, 10 Dec 2002 19:44
126 lines
4675 bytes
"Albe V�" <vaccariTOGLI_QUESTO@hotmail.com> ha scritto nel messaggio
news:fDkJ9.78690$2B1.2187114@twister2.libero.it...
>
> "JtS" <JtS_NOSPAM@PLEASE.it> ha scritto nel messaggio
> news:at1tpg$jhl$1@newsreader.mailgate.org...
> >
> > > In alternativa, � comodissimo creare un file .Csv, che pu� essere
> > benissimo
> > > aperto da Excel e che dal recordset puoi avere con un solo comando
(che
> > non
> > > ricordo, ma dev'essere qualcosa tipo Recordset.GetString o simile).
> >
> > puoi crearti un file di testo con estensione xls dove utilizzi il vbtab
> come
> > separatore di campi
> > funziona, � veloce e excel lo riconosce tranquillamente
>
> Io uso GetString per esportare su CSV. Come vedi, la generazione del file
�
> una unica riga di codice [ADO_RCS.GetString(adClipString, -1, ";",
> vbNewLine, "---")], per cui � velocissima.
>
> Copio-Incollo qui sotto un po' di codice per creare un csv partendo da un
> recordset ADO.
>
> Ciao
>
> Alberto
>
>
>
> Private Sub BTN_Export_CSV_Click()
> Dim ritorno2 As Long
> Dim Percorso As String
> Dim Percorso_Visualizzato As String
> Dim FLD As ADODB.Field
> Dim fil As Integer
> Dim Prima_Riga As String
> Dim Testo_Completo As String
>
> On Error GoTo ErrHandler
>
> CommonDialog1.CancelError = True
>
> If Not CBool(ADO_RCS.State And adStateOpen) Then
>     LBL_Status.Caption = "Prima di esportare i dati occorre
visualizzarli."
>     Exit Sub
> End If
>
> If ADO_RCS.BOF And ADO_RCS.EOF Then
>     LBL_Status.Caption = "Nessun dato da Esportare"
>     Exit Sub
> End If
>
> LBL_Status.Caption = "Procedura di Esportazione in corso..."
> LBL_Status.Refresh
>
> CommonDialog1.FileName = "c:\export.csv"
>
> CommonDialog1.ShowSave
> Percorso = CommonDialog1.FileName
> ChDrive "c:"
>
> If Percorso = vbNullString Then Percorso = "c:\export.csv"
>
> If UCase(Right(Percorso, 4)) <> ".CSV" Then Percorso = Percorso & ".csv"
>
> Percorso_Visualizzato = Percorso
> If Len(Percorso_Visualizzato) > 60 Then
>     Percorso_Visualizzato = Left(Percorso_Visualizzato, 25) & "\..\" &
> Right(Percorso_Visualizzato, 25)
> End If
>
> LBL_Status.Caption = "Esportazione in Corso....."
> LBL_Status.Refresh
>
> fil = FreeFile()
> Open Percorso For Output As #fil
>
> 'Inserisco le intestazioni di colonna
> Prima_Riga = vbNullString
> For Each FLD In ADO_RCS.Fields
>     Prima_Riga = Prima_Riga & """" & FLD.Name & """;"
> Next FLD
> Prima_Riga = Left(Prima_Riga, Len(Prima_Riga) - 1)
>
> 'Creo la stringa complessiva del file
> Testo_Completo = Prima_Riga & vbNewLine &
> ADO_RCS.GetString(adClipString, -1, ";", vbNewLine, "---")
>
> 'Sostituisco le virgole decimali con i punti
> Testo_Completo = Replace(Testo_Completo, ",", ".")
>
> 'Sostituisco il punto e virgola con la virgola
> Testo_Completo = Replace(Testo_Completo, ";", ",")
>
> 'Metto la stringa completa nel file
> Print #fil, Testo_Completo
>
> Close
>
> LBL_Status.Caption = "Esportazione Completata"
>
> Ultima_Operazione = Now
>
> Exit Sub
> ErrHandler:
> LBL_Status.Caption = "Esportazione Annullata"
> Close
>
> End Sub
>
>

Ciao, grazie mille
Lo prover� subito.
Ho provato a seguire la strada di salvare il recordset, ma le uniche opzioni
sono XML e ADO Stream object..
Mi fa specie comunque che con Access si riescano a fare cose che con VB non
si possono riprodurre.

grazie ancora
ciao
Technical Details
Message-ID: <iurJ9.3308$lV4.98938@news2.tin.it>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!bofh.it!news-out.tin.it!news-in.tin.it!news2.tin.it.POSTED!not-for-mail
References: <l55I9.51022$qF1.2069204@news2.tin.it> <9w5I9.64088$3l.1754338@twister1.libero.it> <at1tpg$jhl$1@newsreader.mailgate.org> <fDkJ9.78690$2B1.2187114@twister2.libero.it>

Show Full Headers
Complete Article Headers
X-Google-Language: ITALIAN,ASCII
X-Google-Thread: f94ee,f576374e01de9d68
X-Google-Attributes: gidf94ee,public
X-Google-Thread: 10b997,f576374e01de9d68
X-Google-Attributes: gid10b997,public
X-Google-ArrivalTime: 2002-12-10 11:44:15 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!bofh.it!news-out.tin.it!news-in.tin.it!news2.tin.it.POSTED!not-for-mail
From: "Sergio" <bilboge@inwind.it>
Newsgroups: free.it.visual-basic,it.comp.lang.visual-basic
References: <l55I9.51022$qF1.2069204@news2.tin.it> <9w5I9.64088$3l.1754338@twister1.libero.it> <at1tpg$jhl$1@newsreader.mailgate.org> <fDkJ9.78690$2B1.2187114@twister2.libero.it>
Subject: Re: Spedire un recordset via mail in formato Excel
Lines: 128
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <iurJ9.3308$lV4.98938@news2.tin.it>
Date: Tue, 10 Dec 2002 19:44:14 GMT
NNTP-Posting-Host: 213.45.26.239
X-Complaints-To: newsmaster@tin.it
X-Trace: news2.tin.it 1039549454 213.45.26.239 (Tue, 10 Dec 2002 20:44:14 MET)
NNTP-Posting-Date: Tue, 10 Dec 2002 20:44:14 MET
Organization: TIN