通过asp将excel内容保存到数据库

时间:2010-04-07 09:46:29

标签: excel asp-classic ado

我使用下面的代码将excel文件上传到服务器。现在我需要将它保存到数据库中。任何人都可以指导我们这样做吗?

 Dim SQLStr   
 SQLStr = "INSERT ALL INTO TABLENAME "  
 for each file in filCollection  
   file_name =  file.name   
    path = folderObj & "\" & file_name  
    Set objExcel_chk = CreateObject("Excel.Application")  
    Set ws1 = objExcel_chk.Workbooks.Open(path).Sheets(1)  
     row_cnt = 1  


      'for row_cnt = 6 to 7  
      ' if ws1.Cells(row_cnt,col_cnt).Value <> "" then  
      '  col = col_cnt   
      ' end if  
      'next    
      While (ws1.Cells(row_cnt, 1).Value <> "")   
      for col_cnt = 1 to 10       

       SQLStr = SQLStr & "VALUES('" & ws1.Cells(row_cnt, 1).Value & "')"  
      next  
      row_cnt = row_cnt + 1  
      WEnd  


     'objExcel_chk.Quit  
     objExcel_chk.Workbooks.Close()  
     set ws1 = nothing  
     objExcel_chk.Quit  

     Response.Write(SQLStr)  

      'set filobj = FSYSObj.GetFile (sub_fol_path & "\" & file_name)  
      'filobj.Delete  

    next  
End if  
End If  

1 个答案:

答案 0 :(得分:1)

Read From Excel

上面的链接说明您必须在服务器上安装Excel,并且必须在Excel文件上设置适当的权限才能从中读取。在这个过程之外,我不确定你会怎么做。