Visualizzazione dei risultati da 1 a 9 su 9

Discussione: Importazione da excel

  1. #1

    Importazione da excel

    Buenas noches a todos.

    Apro questa discussione per chè ho un problema che per me non è di facile soluzione:

    Importo in un db mysql, tramite una procedura ASP una serie di campi contenuti in un file excel come da img allegata.

    L'importazione funziona correttamente sino a quando non provo ad importare anche il valore della riga MARCHIO (nell'img allegata ACQUA AL BANCO).

    Posto anche il codice per l'importazione per sapere se avete suggerimenti su come risolvere il problema:

    codice:
    'STRINGA DI CONNESSIONE AL FILE EXCEL
    Dim adoCn
    Set adoCn = CreateObject("ADODB.Connection")
    
    With adoCn
     .Provider="Microsoft.Jet.OLEDB.4.0"
     .ConnectionString="Data Source="&Server.MapPath("VENDUVAL.XLS")&";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
     .Open
    End With
    
    'QUERY DI APERTURA DEL FOGLIO XLS
    Dim doRs
    Set doRs = CreateObject("ADODB.Recordset")
    stQuery = "SELECT * from [VENDUVAL$]"
    
    With doRs
     Set .ActiveConnection = adoCn
     .Open stQuery
    End With
    
    strVariabileData = (doRs(1).name)
    
    Dim adoRs
    Set adoRs = CreateObject("ADODB.Recordset")
    strQuery = "SELECT * from [VENDUVAL$] " 
    strQuery = strQuery & " WHERE " 
    strQuery = strQuery & " ["&strVariabileData&"] <> 'Codice a barre' " 
    strQuery = strQuery & " and ["&strVariabileData&"] <> 'DALLA DATA:'  " 
    strQuery = strQuery & " and ["&strVariabileData&"] <> 'Categoria merceologica:'  " 
    strQuery = strQuery & " and ["&strVariabileData&"] <> 'Linea:'"
    
    With adoRs
     Set .ActiveConnection = adoCn
     .Open strQuery
    End With
     
    If adoRs.EOF then
    
    response.write "Nessun dato da importare"
    
    else
    
    for i=0 to adoRs.fields.count -1
       response.Write(adoRs(i).name&" ") 'visualizzo i nomi dei campi per sfizio
    next
       response.Write("
    
    NUMERO CAMPI:
    "&adoRs.fields.count&"
    
    ") ' lo stesso il numero dei campi
     
    adoRs.MoveFirst 
    Do While Not adoRs.Eof
    
    
    for i=0 to adoRs.fields.count -1
        valore_campo = adoRs(i)
    next
    
    'STAMPO LE RIGHE CHE MI INTERESSANO
    response.write adoRs(1)  &" ---> adoRs1
    "
    response.write adoRs(3)  &" ---> adoRs3
    "
    response.write adoRs(4)  &" ---> adoRs4
    "
    Immagini allegate Immagini allegate

  2. #2
    ciao bello. qual'è il problema?

  3. #3
    Originariamente inviato da optime
    ciao bello. qual'è il problema?
    Ciao Opt e grazie per la risposta !

    Il problema è che se nella query di apertura del foglio excel seleziono anche il campo che contiene il valore della riga MARCHIO perdo tutte le righe successive:

    Cioè con MARCHIO incluso nella query ottengo:

    codice:
    Marchio: ---> adoRs1
    ---> adoRs3
    ---> adoRs4
    Con MARCHIO escluso dalla query ottengo:

    codice:
    85 ---> adoRs1
    1/2 LT NATURALE B ---> adoRs3
    1/2 LT MINERALE NATURALE AL BANCO ---> adoRs4
    E' un problema di scorrimento righe del file excel... ???

  4. #4

  5. #5
    Tabella completa
    Immagini allegate Immagini allegate

  6. #6
    faccio fatica a seguirti... però con adors(1), (2), (3) ecc si scorrono le colonne, non le righe

    per scorrere le righe devi fare una adors.movenext...

  7. #7
    Grazie per aver risposto.

    Che altro tipo di info ti è necessaria?

    Hai visto la tabella excel di riferimento?

    L'img che ho postato non è chiara?

    Intanto ecco il codice:

    codice:
    <% 
    
    Dim adoCn
    Set adoCn = CreateObject("ADODB.Connection")
    
    With adoCn
     .Provider="Microsoft.Jet.OLEDB.4.0"
     .ConnectionString="Data Source="&Server.MapPath("VENDUVAL.XLS")&";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
     .Open
    End With
    
    If err.number <> 0 Then 
    Pagina = Request.ServerVariables("url") 
     
                    %>
     
    <script language="javascript">
      alert("Errore nel formato del file.\nERRORE N. <%=err.number%>\n<%=err.Description%>\n<%=err.Source%>\n<%=pagina%>");
      location.href("default.asp");
    </script>
          
            <%
            Response.End
        End If
        
    strVariabileDataVenduto = formatDBDate(Date(),"mysql")
    DataVenduto = Upload.Form("DataVenduto")
    strDataVenduto = formatDBDate(DataVenduto,"mysql")
    
    Dim doRs
    Set doRs = CreateObject("ADODB.Recordset")
    stQuery = "SELECT * from [VENDUVAL$]"
    
    With doRs
     Set .ActiveConnection = adoCn
     .Open stQuery
    End With
    
    strVariabileData = (doRs(1).name)
    strVariabileMarchio = (doRs(2).name)
    
    response.write strVariabileMarchio &"
    
    "
    
    Dim adoRs
    Set adoRs = CreateObject("ADODB.Recordset")
    strQuery = "SELECT * from [VENDUVAL$] " 
    strQuery = strQuery & " WHERE " 
    strQuery = strQuery & " ["& strVariabileData &"] <> 'Codice a barre' " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'DALLA DATA:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Categoria merceologica:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Marchio:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Linea:'"
    
    response.write strQuery &"
    
    "
    
    With adoRs
     Set .ActiveConnection = adoCn
     .Open strQuery
    End With
     
    If adoRs.EOF then
    
    %>
    
    <script language="javascript">
    
    function NumeroCasuale(Da,A) {
      return Math.floor((A-Da+1) * Math.random() +Da);
    }
    
      alert("Nessun dato da importare.");
      location.href("../mySql/default.asp?nocache="+NumeroCasuale(1,99999);
    </script>
    
    <%
    
    Else
     
    for i=0 to adoRs.fields.count -1
       response.Write(adoRs(i).name&" ") 'visualizzo i nomi dei campi per sfizio
    next
       response.Write("
    
    NUMERO CAMPI: "&adoRs.fields.count&"
    
    ") ' lo stesso il numero dei campi
    
     
    adoRs.MoveFirst 
    Do While Not adoRs.Eof
     
    for i = 0 to adoRs.fields.count -1
       valore_campo = adoRs(i)
    next
    
    response.write adoRs(1)  &" ---> adoRs1
    "
    response.write adoRs(3)  &" ---> adoRs3
    "
    response.write adoRs(4)  &" ---> adoRs4
    "
    response.write adoRs(10) &" ---> adoRs10
    "
    response.write adoRs(11) &" ---> adoRs11
    "
    response.write adoRs(13) &" ---> adoRs13
    "
    response.write adoRs(15) &" ---> adoRs15
    "
    response.write adoRs(16) &" ---> adoRs16
    "
    response.write adoRs(17) &" ---> adoRs17
    "
    response.write adoRs(18) &" ---> adoRs18
    
    "

  8. #8
    1. non vedo dove scorri la tabella
    2. lo scorrimento dei campi passa per un array che non riempi
    3. adors1, 2, 3 ecc dove li riempi?

    righetto, stacci attento...

  9. #9
    Hai ragione; pensavo che il problema fosse circoscritto al pezzo di codice postato.

    Eccoti il codice completo, spero tu possa aiutarmi a risolvere qeusto enigma, grazie.

    codice:
    
    <% 
    
    Dim adoCn
    Set adoCn = CreateObject("ADODB.Connection")
    
    With adoCn
     .Provider="Microsoft.Jet.OLEDB.4.0"
     .ConnectionString="Data Source="&Server.MapPath("VENDUVAL.XLS")&";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
     .Open
    End With
    
    If err.number <> 0 Then 
    Pagina = Request.ServerVariables("url") 
     
                    %>
     
    <script language="javascript">
      alert("Errore nel formato del file.\nERRORE N. <%=err.number%>\n<%=err.Description%>\n<%=err.Source%>\n<%=pagina%>");
      location.href("default.asp");
    </script>
          
            <%
            Response.End
        End If
        
    strVariabileDataVenduto = formatDBDate(Date(),"mysql")
    DataVenduto = Upload.Form("DataVenduto")
    strDataVenduto = formatDBDate(DataVenduto,"mysql")
    
    Dim doRs
    Set doRs = CreateObject("ADODB.Recordset")
    stQuery = "SELECT * from [VENDUVAL$]"
    
    With doRs
     Set .ActiveConnection = adoCn
     .Open stQuery
    End With
    
    strVariabileData = (doRs(1).name)
    strVariabileMarchio = (doRs(2).name)
    
    response.write strVariabileMarchio &"
    
    "
    
    Dim adoRs
    Set adoRs = CreateObject("ADODB.Recordset")
    strQuery = "SELECT * from [VENDUVAL$] " 
    strQuery = strQuery & " WHERE " 
    strQuery = strQuery & " ["& strVariabileData &"] <> 'Codice a barre' " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'DALLA DATA:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Categoria merceologica:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Marchio:'  " 
    strQuery = strQuery & " and ["& strVariabileData &"] <> 'Linea:'"
    
    response.write strQuery &"
    
    "
    
    With adoRs
     Set .ActiveConnection = adoCn
     .Open strQuery
    End With
     
    If adoRs.EOF then
    
    %>
    
    <script language="javascript">
    
    function NumeroCasuale(Da,A) {
      return Math.floor((A-Da+1) * Math.random() +Da);
    }
    
      alert("Nessun dato da importare.");
      location.href("../mySql/default.asp?nocache="+NumeroCasuale(1,99999);
    </script>
    
    <%
    
    Else
     
    for i=0 to adoRs.fields.count -1
       response.Write(adoRs(i).name&" ") 'visualizzo i nomi dei campi per sfizio
    next
       response.Write("
    
    NUMERO CAMPI: "&adoRs.fields.count&"
    
    ") ' lo stesso il numero dei campi
    
     
    adoRs.MoveFirst 
    Do While Not adoRs.Eof
     
    for i = 0 to adoRs.fields.count -1
       valore_campo = adoRs(i)
    next
    
    response.write adoRs(1)  &" ---> adoRs1
    "
    response.write adoRs(3)  &" ---> adoRs3
    "
    response.write adoRs(4)  &" ---> adoRs4
    "
    response.write adoRs(10) &" ---> adoRs10
    "
    response.write adoRs(11) &" ---> adoRs11
    "
    response.write adoRs(13) &" ---> adoRs13
    "
    response.write adoRs(15) &" ---> adoRs15
    "
    response.write adoRs(16) &" ---> adoRs16
    "
    response.write adoRs(17) &" ---> adoRs17
    "
    response.write adoRs(18) &" ---> adoRs18
    
    "
    
    strVarComodo1 = CDBL(adoRs(1) & "") 
    strVarComodo1 = Replace(strVarComodo1, ",", ".")
    
    strVarComodo10 = CDBL(adoRs(10) & "") 
    strVarComodo10 = Replace(strVarComodo10, ",", ".")
    
    strVarComodo11 = CDBL(adoRs(11) & "") 
    strVarComodo11 = Replace(strVarComodo11, ",", ".")
    
    strVarComodo13 = CDBL(adoRs(13) & "") 
    strVarComodo13 = Replace(strVarComodo13, ",", ".")
    
    strVarComodo15 = CDBL(adoRs(15) & "") 
    strVarComodo15 = Replace(strVarComodo15, ",", ".")
    
    strVarComodo16 = CDBL(adoRs(16) & "") 
    strVarComodo16 = Replace(strVarComodo16, ",", ".")
    
    IF IsNull(adoRs(17)) THEN 
      strVarComodo17 = (adoRs(17) & "")
      strVarComodo17 = Replace(strVarComodo17, ",", ".")
    else
      strVarComodo17 = CDBL(adoRs(17) & "") 
      strVarComodo17 = Replace(strVarComodo17, ",", ".")
    end if
    
    IF IsNull(adoRs(18)) THEN 
      strVarComodo18 = (adoRs(18) & "")
      strVarComodo18 = Replace(strVarComodo18, ",", ".")
    else
      strVarComodo18 = CDBL(adoRs(18) & "") 
      strVarComodo18 = Replace(strVarComodo18, ",", ".")
    end if
    
    If IsNull(adoRs(17)) then 
       strSQL = "INSERT INTO tabellavenduto " 
       strSQL  = strSQL & " (DataVenduto, " 
       strSQL  = strSQL & "  DataCaricamento, "
       strSQL  = strSQL & "  CodiceBarre, " 
       strSQL  = strSQL & "  CodiceArrivo, " 
       strSQL  = strSQL & "  Descrizione, " 
       strSQL  = strSQL & "  Esistenza, " 
       strSQL  = strSQL & "  Qta, " 
       strSQL  = strSQL & "  ValoreMov, " 
       strSQL  = strSQL & "  ValoreCosto, " 
       strSQL  = strSQL & "  Differenza, " 
       strSQL  = strSQL & "  Margine) " 
       strSQL  = strSQL & "  VALUES " 
       strSQL  = strSQL & " ("& strDataVenduto &", " 
       strSQL  = strSQL & "  "& strVariabileDataVenduto &", "
       strSQL  = strSQL & "  "& strVarComodo1 &", " 
       strSQL  = strSQL & " '"& adoRs(3) &"', " 
       strSQL  = strSQL & " '"& adoRs(4) &"', " 
       strSQL  = strSQL & "  "& strVarComodo10 &", " 
       strSQL  = strSQL & "  "& strVarComodo11 &", " 
       strSQL  = strSQL & "  "& strVarComodo13 &", " 
       strSQL  = strSQL & "  "& strVarComodo15 &", " 
       strSQL  = strSQL & "  "& strVarComodo16 &", " 
       strSQL  = strSQL & "  "& strVarComodo18 &")" 
    else
       strSQL = "INSERT INTO tabellavenduto " 
       strSQL  = strSQL & " (DataVenduto, " 
       strSQL  = strSQL & "  DataCaricamento, "
       strSQL  = strSQL & "  CodiceBarre, " 
       strSQL  = strSQL & "  CodiceArrivo, " 
       strSQL  = strSQL & "  Descrizione, " 
       strSQL  = strSQL & "  Esistenza, " 
       strSQL  = strSQL & "  Qta, " 
       strSQL  = strSQL & "  ValoreMov, " 
       strSQL  = strSQL & "  ValoreCosto, " 
       strSQL  = strSQL & "  Differenza, " 
       strSQL  = strSQL & "  Margine) " 
       strSQL  = strSQL & "  VALUES " 
       strSQL  = strSQL & " ("& strDataVenduto &", " 
       strSQL  = strSQL & "  "& strVariabileDataVenduto &", " 
       strSQL  = strSQL & "  "& strVarComodo1 &", " 
       strSQL  = strSQL & " '"& adoRs(3) &"', " 
       strSQL  = strSQL & " '"& adoRs(4) &"', " 
       strSQL  = strSQL & "  "& strVarComodo10 &", " 
       strSQL  = strSQL & "  "& strVarComodo11 &", " 
       strSQL  = strSQL & "  "& strVarComodo13 &", " 
       strSQL  = strSQL & "  "& strVarComodo15 &", " 
       strSQL  = strSQL & "  "& strVarComodo16 &", " 
       strSQL  = strSQL & "  "& strVarComodo17 &")" 
    end if
    objconn.Execute(strSQL)
       
       response.write strSQL &"
    "
    
    adoRs.MoveNext 
    Loop
    end if 
    
    doRs.close
    Set doRs = Nothing
    
    adoRs.close
    Set adoRs = Nothing
    
    adoCn.Close
    Set adoCn = Nothing
    
    
    %>
    
    
    <script language="javascript">
    
    function NumeroCasuale(Da,A) {
      return Math.floor((A-Da+1) * Math.random() +Da);
    }
    
      alert("Importazione eseguita correttamente.\nIl file: <%=NewFileName%>\nè stato importato nel DataBase Magazzino.");
      location.href("../mySql/default.asp?nocache="+NumeroCasuale(1,99999);
    </script>

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