🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Spedire un recordset via mail in formato Excel

#3019
From: Albe V�
Date: Tue, 10 Dec 2002 11:55
108 lines
4130 bytes
"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
Technical Details
Message-ID: <fDkJ9.78690$2B1.2187114@twister2.libero.it>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!ossa.telenet-ops.be!skynet.be!skynet.be!newsfeeder.edisontel.com!news.mailgate.org!nntp.infostrada.it!twister2.libero.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>

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 03:55:57 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!ossa.telenet-ops.be!skynet.be!skynet.be!newsfeeder.edisontel.com!news.mailgate.org!nntp.infostrada.it!twister2.libero.it.POSTED!not-for-mail
From: "Albe V�" <vaccariTOGLI_QUESTO@hotmail.com>
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>
Subject: Re: Spedire un recordset via mail in formato Excel
Lines: 110
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: <fDkJ9.78690$2B1.2187114@twister2.libero.it>
Date: Tue, 10 Dec 2002 11:55:55 GMT
NNTP-Posting-Host: 151.38.59.196
X-Complaints-To: abuse@net24.it
X-Trace: twister2.libero.it 1039521355 151.38.59.196 (Tue, 10 Dec 2002 12:55:55 MET)
NNTP-Posting-Date: Tue, 10 Dec 2002 12:55:55 MET
Organization: [Infostrada]