Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/11/2013, 14:12
kire94
 
Fecha de Ingreso: enero-2006
Mensajes: 169
Antigüedad: 20 años, 8 meses
Puntos: 0
Respuesta: Error al subir archivo ASPUpload

Código PHP:
 <form name="Form_SubirExcel" action="carga_distribucion.asp?subir_archivo=1" method="post" enctype="multipart/form-data">
        <
table width="750" border="0" align="center" height="35">
          <
tr class= "Titulo"> 
            <
td>Carga de distribuci&oacute;n por paquetes</td>
            <
td><!--<a href="cot_autoriza.asp"><img src="http://www.forosdelweb.com/f15/fle_colores_izq.jpg" width="30" border="0" height="34"></a>-->
                <
a href="javascript:window.history.back();"><img src="http://www.forosdelweb.com/f15/fle_colores_izq.jpg" width="30" border="0" height="34"></a>
            </
td>
          </
tr>
        </
table>
        <
table width="750" border="0" cellspacing="0" cellpadding="0" align="center">
            <
tr><td colspan="5"> 
                <
table width="750" border="1" cellspacing="0" cellpadding="0" bordercolor="#C0C0C0" align="center">
                    <
tr class="Titulotabla"> 
                        <
td colspan="2">Seleccione archivo</td>
                    </
tr>
                    <
tr class="fondotabla2"> 
                        <
td align="right"><input type="file" name="frmArchivo" /></td>
                        <
td><input type="submit" value="Subir archivo" onclick="return validate_file_format('frmArchivo','xls,xlsx')" /></td>
                    </
tr>
                </
table>
            </
td></tr>
        
        </
table>
        </
form>
<%
    if 
Request.QueryString("subir_archivo")=1 then
        
'Dim oConexion 
        Dim aDatos, aInserciones, msjError, reg_vacio, reg_num
        Dim sFilePath, sDataDir, sSheetName, sFileConnectionString, sFileSQL, oFileCN
        Dim oRS, aSourceData, iCont
        

        msjError = ""
        reg_vacio = 0
        reg_num = 0

        '
Set oConexion = Server.CreateObject("ADODB.Connection")

        
sFilePath = server.MapPath("Carpeta\excel.xls") 'path del archivo xls
        sDataDir = server.MapPath("carpeta") '
path de directotio que lo contiene
        sSheetName 
= "Hoja1" ' nombre de la hoja donde estan los registros

        '
response.Write sFilePath

        sFileConnectionString 
= "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="&sFilePath&";DefaultDir="&sDataDir&";"
        
sFileSQL = "SELECT * FROM [" & sSheetName & "$]"
        
set oFileCN = server.createobject("ADODB.Connection") 'creo objeto adodb
        oFileCN.Open sFileConnectionString '
abro el exel
        set oRS 
= oFileCN.Execute(sFileSQL) 'selecciono los registros
        if not oRS.EOF then '
si es distinto de EOF obtengo un array con los valores de las columnas
            aSourceData 
= oRS.getRows() ' asigna las filas a la variable aSourceData 
        end if

        '
SI DIO CLICK EN "CARGAR DISTRIBUCION" SE PROCEDE A GUARDAR LOS REGISTROS EN LA TABLA
        
if request.QueryString("btn_carga_dist")=1 then
            dim datos_excel
(11) '11 por que son del 0 al 11, en total, 12 columnas en el excel

            Do While NOT oRs.EOF
                For iCont = 0 to oRs.Fields.Count - 1
                    if oRs.Fields(iCont)<>"" then
                        reg_vacio = reg_vacio + 0
                    else
                        reg_vacio = reg_vacio + 1
                    end if
                Next


                if reg_vacio <> 12 then
                    response.Write "reg_num= " & reg_num & "<br>"
                    For iCont = 0 to oRs.Fields.Count - 1
                        datos_excel(iCont) =  oRs.Fields(iCont)
                        response.Write "Posicion(" & iCont & ")= " & datos_excel(iCont) & "<br>"
                    Next
                end if

                    '
For iCont = 0 to oRs.Fields.Count - 1
                        
'response.Write "Posicion(" & iCont & ")= " & datos_excel(iCont) & "<br>"
                   '
Next
    
                
if reg_vacio <> 12 then
                    oRs
.MoveNext
                    reg_num 
= reg_num + 1
                    reg_vacio 
= 0
                
else
                    exit Do
                
end if
            
Loop
        
else
            
'Validamos que los campos obligatorios esten llenos en el excel
            oRs.MoveFirst
            Do While NOT oRs.EOF
                For iCont = 0 to oRs.Fields.Count - 1
                    if oRs.Fields(iCont)<>"" then
                        reg_vacio = reg_vacio + 0
                    else
                        reg_vacio = reg_vacio + 1
                    end if
                Next

                if reg_vacio <> 12 then 
                    For iCont = 0 to oRs.Fields.Count - 1
                        if oRs.Fields(0)<>"" then
                        else
                            msjError = "LA COLUMNA '
NO SUCURSAL RECEPTORA' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(4)<>"" then
                        else
                            msjError = "LA COLUMNA '
PAQUETES' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(6)<>"" then
                        else
                            msjError = "LA COLUMNA '
SKU' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                        if oRs.Fields(7)<>"" then
                        else
                            msjError = "LA COLUMNA '
ODTi' NO PUEDE ESTAR VACIA EN EL ARCHIVO EXCEL"
                            exit for
                        end if
                    Next
                end if

                if reg_vacio <> 12 AND msjError="" then
                    oRs.MoveNext
                    reg_vacio = 0
                else
                    exit Do
                end if
            Loop


            if msjError<>"" then '
Si existe error en el archivo excel, indicamos el mismo
                Response
.Write "<p align='center'><font color='RED'><strong>" & msjError & "</strong></font></p>"
            
else 'Pintamos el archivo excel
                '
Mostramos los nombres de los campos (cabecera) 
                
response.Write "<table width='750' border='0' cellspacing='0' cellpadding='0' align='center'>"
                
response.Write "<tr><td>" 
                
response.Write "<table width='750' border='1' cellspacing='0' cellpadding='0' bordercolor='#C0C0C0' align='center'>"
                
response.Write "<tr class='Titulotabla'>"
                
For iCont = 0 to oRs.Fields.Count - 1 
                  Response
.Write "<td>" & oRs.Fields(iCont).name & "<td/>"
                
Next 
                response
.Write "</tr>"

                'response.Write "error = " & msjError
    
                oRs.MoveFirst
                Do While NOT oRs.EOF
        
                    For iCont = 0 to oRs.Fields.Count - 1
                        if oRs.Fields(iCont)<>"" then
                            reg_vacio = reg_vacio + 0
                        else
                            reg_vacio = reg_vacio + 1
                        end if
                    Next
        
                    if reg_vacio <> 12 then
                        response.Write "<tr class='
fondotabla2>"
                        For iCont = 0 to oRs.Fields.Count - 1
                            if oRs.Fields(iCont)<>"" then    
                                Response.Write "
<td>" & oRs.Fields(iCont) & "<td/>"
                            else
                                Response.Write "
<td>&nbsp;<td/>"
                            end if
                        Next
                    end if
                    response.Write "
</tr>"
        
                    if reg_vacio <> 12 then
                        oRs.MoveNext
                        reg_vacio = 0
                    else
                        exit Do
                    end if

                Loop
                response.Write "
</td></tr>"
                response.Write "
</table>"
            end if
        end if

        oRS.Close
        set oRS = nothing
        oFileCN.Close
        set oFileCN = nothing
    end if
%>

    </body>
</html> 
Gracias de antemano.
__________________
"La adulación es una moneda que empobrece al que la recibe"