Condividi:        

[ASP] Leggere un XLS

Problemi di HTML? Di PHP, ASP, .NET, JSP, Perl, SQL, JavaScript, Visual Basic..?
Vuoi realizzare programmi in C, C++, Java, Ruby o Smalltalk, e non sai da che parte cominciare?
Entra qui e troverai le risposte!

Moderatori: Anthony47, Triumph Of Steel, archimede

[ASP] Leggere un XLS

Postdi Triumph Of Steel » 26/05/05 16:59

Tramite ASP (non .NET), dovrei leggere in un file XLS.

googlando e provando i vari codici in giro non riesco a far funzionare nulla.

non credo sia un problema di codice, ma forse di sistema.

il codice che uso è questo:

Codice: Seleziona tutto
fileXLS   = Server.MapPath("xls/test2.xls")
Response.write "Reading file: " & fileXLS & "<br>"

Set Conn   = Server.CreateObject("ADODB.Connection")
str         = "DRIVER={Microsoft Excel Driver (*.xls)}; DBQ=" & fileXLS & "; DriverID=790"
response.write str & "<br>"
Conn.Open   str

Set rs   = Server.CreateObject("ADODB.Recordset")
strSQL   = "SELECT * FROM theList"
rs.Open SQL, Conn
rs.movefirst
do while not rs.eof
   response.Write(rs("artist")&" | "&rs("album")& "<br>")
   rs.movenext
Loop

rs.close
set rs=nothing
conn.close
set conn=nothing


aprendo la pagina, mi viene fuori questo errore

Pagina ASP ha scritto:Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Excel Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xfac Thread 0x764 DBC 0x1617da4 Excel'.

/xlsReader.asp, line 9


Il percorso al file è giusto!
Ho cercato l'errore sempre in rete, ho settato i permessi ad EVERYONE - FULL CONTROL, nada!

Mi pare di aver capito che usando il metodo

DRIVER={Microsoft Excel Driver (*.xls)};

non c'è bisogno di settare il DSN.
Ho provato anche a settare il DSN, ma stesso errore (oppure dice che il DSN non si trova)

idee?
Avatar utente
Triumph Of Steel
Moderatore
 
Post: 7852
Iscritto il: 22/08/01 01:00

Sponsor
 

Postdi archimede » 27/05/05 07:51

Mi sa che è un problema del tuo server. Il seguente codice a me funziona:
Codice: Seleziona tutto
<%
fileXLS  = Server.MapPath("test.xls")
Response.Write "Reading file: " & fileXLS & "<br>"
Set Conn = Server.CreateObject("ADODB.Connection")
str      = "DRIVER={Microsoft Excel Driver (*.xls)}; DBQ=" & fileXLS & "; DriverID=790"
Response.Write str & "<br>"
Conn.Open str

Set rs   = Server.CreateObject("ADODB.Recordset")
strSQL   = "SELECT * FROM theList"
rs.Open strSQL, Conn
rs.movefirst
Do While Not rs.EOF
   Response.Write(rs("artist") & " | " & rs("album") & "<br>")
   rs.movenext
Loop

rs.close
set rs = Nothing
conn.close
set conn = Nothing
%>
HTH.

Alessandro
archimede
Moderatore
 
Post: 2851
Iscritto il: 07/11/02 12:41
Località: Genova

Postdi Triumph Of Steel » 27/05/05 09:50

è quello che temevo infatti...
il problema poi si pone anche sul server online, mannaggia!

farò altre prove.. grazie!
Avatar utente
Triumph Of Steel
Moderatore
 
Post: 7852
Iscritto il: 22/08/01 01:00

Postdi Triumph Of Steel » 27/05/05 11:16

aiutato da un amico, alla fine funziona!
c'erano alcuni errori nel codice (che mi erano proprio sfuggiti), e molto probabilmente anche il percorso non era corretto, in più, l'excel NON deve essere aperto mentre si legge con ASP

Codice: Seleziona tutto
fileXLS   = Server.MapPath("/html/XLSReader/xls/test.xls")
'Response.write "Reading file: " & fileXLS & "<br>"

Set Conn   = Server.CreateObject("ADODB.Connection")
str         = "DRIVER={Microsoft Excel Driver (*.xls)}; "
str         = str & "DBQ=" & fileXLS & ""

'response.write str & "<br>"
Conn.Open   str

Set RS   = Server.CreateObject("ADODB.Recordset")
strSQL   = "SELECT * FROM [Redazione$]"
RS.Open strSQL, Conn
RS.movefirst
Do While NOT RS.EOF
   response.Write RS("RagioneSociale") & " <br> " & RS("PartitaIVA") & " <br> " & RS("CodiceCliente") & "<br>"
   RS.movenext
Loop

RS.close
set RS      = nothing
Conn.close
set Conn   = nothing


nella stringa di connessione, si può usare anche il DriverID per specificare la versione di Excel in uso, credo sia opzionale.

Codice: Seleziona tutto
' Microsoft Excel 3.0 or 4.0
Driver={Microsoft Excel Driver (*.xls)}; DBQ=c:\temp; DriverID=278

' Microsoft Excel 5.0/7.0
Driver={Microsoft Excel Driver (*.xls)}; DBQ=c:\temp\sample.xls; DriverID=22

' Microsoft Excel 97
Driver={Microsoft Excel Driver (*.xls)}; DBQ=c:\temp\sample.xls; DriverID=790


saluti!
Avatar utente
Triumph Of Steel
Moderatore
 
Post: 7852
Iscritto il: 22/08/01 01:00


Torna a Programmazione


Topic correlati a "[ASP] Leggere un XLS":


Chi c’è in linea

Visitano il forum: Nessuno e 12 ospiti