è possibile convertire la data dal formato 20050614 al 10/06/2005 durante l'esportazione dei dati in un file exel?
è possibile convertire la data dal formato 20050614 al 10/06/2005 durante l'esportazione dei dati in un file exel?
Cvs non è un file excel.
E' un file di testo con dei caratteri speciali che indicano la suddivisione delle informazioni.
Comunque la risposta è si, puoi modificarla.
Manca di sapere dove lo devi generare, come , come funziona, in che contesto, in quale linguaggio per entrare nel dettaglio della questione
ok scusa![]()
<%
strconn = ""
Set objconn = Server.CreateObject("ADODB.Connection")
Set objrs = Server.CreateObject("ADODB.Recordset")
objconn.open strconn
sql_0 = "SELECT * from FANS"
nomefile = "export_iscritti_FansClub_" & year(now) & right("00" & month(now),2) & right("00" & day(now),2) & right("00" & hour(now),2) & right("00" & minute(now),2) & right("00" & second(now),2) & ".csv"
intestazione = "NOME; COGNOME; TELEFONO; CELLULARE; E-MAIL; INDIRIZZO; CAP; CITTA'; PROVINCIA; PAESE; FASCIA ETA'; SESSO; CODICE PRODOTTO; TAGLIA; COLORE; DATA ACQUISTO; LUOGO; DA CONTATTARE VIA; DATA ISCRIZIONE"
arrayCampi = Array("FANS_NOME", "FANS_COGN", "FANS_TELE", "FANS_CELL", "FANS_MAIL", "FANS_INDI", "FANS_CAP", "FANS_CITT", "FANS_PROV", "FANS_PAES", "FANS_ETA", "FANS_SEX", "FANS_CODI", "FANS_TAGL", "FANS_COLO", "FANS_ACQU", "FANS_LUOG", "FANS_CONT","FANS_DATA")
set objrs = objconn.execute(sql_0)
if not(objrs.eof or objrs.bof) then
set objFso = Server.CreateObject("Scripting.FileSystemObject")
set objText = objFso.CreateTextFile(Server.MapPath("/temp/" & nomefile),true,false)
objText.WriteLine(intestazione)
do while not(objrs.eof or objrs.bof)
myString = ""
for i = 0 to Ubound(ArrayCampi)
myString = myString & ";" & strRevert(objrs.fields(arrayCampi(i)).value)
next
myString = Right(myString,(Len(myString)-1))
objText.WriteLine(myString)
objrs.movenext
loop
objText.close
Set objText = Nothing
Set objFso = Nothing
End If
dim objStream, myFILE, fname
Const adTypeBinary = 1
Const adReadAll = -1
fname = request("nomefile")
myFILE = Server.MapPath("/temp/" & nomefile)
set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile myFILE
Response.Expires = 0
Response.Buffer = true
Response.ContentType = "application/octet-stream"
Response.Addheader "Content-Disposition", "attachment; filename=" & nomefile
Response.Addheader "Content-Length", objStream.size
Response.BinaryWrite(objStream.Read(adReadAll))
objStream.Close
set objStream = nothing
Response.End
%>
ecco il codice
Salvi il file e lo rileggi in binario? Perchè mai? Che giro fai?
Comunque, per arrivare al punto. Puoi fare in diversi modi.
L'importante è
che in questo for
Hai un elemento che ti faccia capiere che il campo in questione è una data.codice:for i = 0 to Ubound(ArrayCampi) myString = myString & ";" & strRevert(objrs.fields(arrayCampi(i)).value) next
In praatica io voglio che lo scarichino immediatamente senza farglielo generare in una cartella per poi farlo scricare da un'altra pagina così funziona ance se presumo ci siano metodi più efficaci per quanto riguarda la data non ho capito nulla :master:
Iniziamo con un po' d'ordine.
codice:<% strconn = ".." Set objconn = Server.CreateObject("ADODB.Connection") objconn.open strconn sql_0 = "SELECT * from FANS" intestazione = "NOME; COGNOME; TELEFONO; CELLULARE; E-MAIL; INDIRIZZO; CAP; CITTA'; PROVINCIA; PAESE; FASCIA ETA'; SESSO; CODICE PRODOTTO; TAGLIA; COLORE; DATA ACQUISTO; LUOGO; DA CONTATTARE VIA; DATA ISCRIZIONE" arrayCampi = Array("FANS_NOME", "FANS_COGN", "FANS_TELE", "FANS_CELL", "FANS_MAIL", "FANS_INDI", "FANS_CAP", "FANS_CITT", "FANS_PROV", "FANS_PAES", "FANS_ETA", "FANS_SEX", "FANS_CODI", "FANS_TAGL", "FANS_COLO", "FANS_ACQU", "FANS_LUOG", "FANS_CONT","FANS_DATA") set objrs = objconn.execute(sql_0) if Not(objrs.eof) then myString = "" Nomefile = "export_iscritti_FansClub_" & year(now) & right("00" & month(now),2) & right("00" & day(now),2) & right("00" & hour(now),2) & right("00" & minute(now),2) & right("00" & second(now),2) & ".csv" set objFso = Server.CreateObject("Scripting.FileSystemObject") set objText = objFso.CreateTextFile(Server.MapPath("/temp/" & nomefile),true,false) objText.WriteLine(intestazione) do while not(objrs.eof or objrs.bof) for i = 0 to Ubound(ArrayCampi) myString = myString & ";" & strRevert(objrs.fields(arrayCampi(i)).value) next myString = Right(myString,(Len(myString)-1)) objText.WriteLine(myString) objrs.movenext loop objText.close Set objText = Nothing Set objFso = Nothing fname = request("nomefile") Response.ContentType = "application/octet-stream" Response.Addheader "Content-Disposition", "attachment; filename=" & nomefile Response.Write myString set objStream = nothing End If Response.End %>
Grazie dovresti mettere un angelo come avatar
![]()
..ehehe...ma non funziona....aspetta....
Nella variabile ListaCampiData metti tutti i campi data divisi dal ;codice:<% Function Converti(Valore) 'Implementa questa funzione per la conversione. End Function StringConnection = "..." SqlString = "SELECT * from FANS" Intestazione = "NOME; COGNOME; TELEFONO; CELLULARE; E-MAIL; INDIRIZZO; CAP; CITTA'; PROVINCIA; PAESE; FASCIA ETA'; SESSO; CODICE PRODOTTO; TAGLIA; COLORE; DATA ACQUISTO; LUOGO; DA CONTATTARE VIA; DATA ISCRIZIONE" ArrayCampi = Array("FANS_NOME", "FANS_COGN", "FANS_TELE", "FANS_CELL", "FANS_MAIL", "FANS_INDI", "FANS_CAP", "FANS_CITT", "FANS_PROV", "FANS_PAES", "FANS_ETA", "FANS_SEX", "FANS_CODI", "FANS_TAGL", "FANS_COLO", "FANS_ACQU", "FANS_LUOG", "FANS_CONT","FANS_DATA") ListaCampiData = "FANS_DATA" Set Conn = Server.CreateObject("ADODB.Connection") Conn.open StringConnection set Rs = Conn.execute(SqlString) if Not(objrs.eof) then Contenuto = "" Nomefile = "export_iscritti_FansClub_" & year(now) & right("00" & month(now),2) & right("00" & day(now),2) & right("00" & hour(now),2) & right("00" & minute(now),2) & right("00" & second(now),2) & ".csv" do while not(objrs.eof or objrs.bof) Riga = "" for Each Elm In ArrayCampi If InStr(1,";" & ListaCampiData & ";",";" & Elm & ";",1)>0 then Valore = Converti(Rs(Elm)) else Valore = strRevert(Rs(Elm)) End if Riga = Riga & ";" & Valore next Contenuto = Contenuto & Mid(Riga,2) & VbCrLf objrs.movenext loop set Fso = Server.CreateObject("Scripting.FileSystemObject") set File = Fso.CreateTextFile(Server.MapPath("/temp/" & nomefile),true,false) File.WriteLine(intestazione) File.Write(Contenuto) File.close Set File = Nothing Set Fso = Nothing fname = request("nomefile") Response.ContentType = "application/octet-stream" Response.Addheader "Content-Disposition", "attachment; filename=" & nomefile Response.Write Contenuto set objStream = nothing End If Rs.Close() Conn.Close() Set Rs = Nothing Set Conn = Nothing Response.End %>
Adesso ti manca solo la conversione della data.
Il codice può essere ancora migliorato.... ma l'importante che funziona....