티스토리 뷰

개발

엑셀파일 업로드 처리

Hello™ 2013. 8. 27. 10:30

엑셀 업로드에 관련되어 xls, xlsx의 차이점만 썼는데, 이번에는 Full로


아래는 소스

#################################### 엑셀 올리는 파일업로드

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

 <head>

  <title> New Document </title>

<script type="text/javascript">

<!--

function InputCk(form) {

if(confirm("등록하시겠습니까?\n확인을 누르시면, 등록이 처리됩니다.")) {

form.action="엑셀처리파일.asp";

form.submit();

}

}

//-->

</script>

 </head>


 <body>

<form name="sbform" enctype="multipart/form-data" method="post">

<input type="file" name="file1" style="width:300px" class="input"> 

<input type="button"  value="엑셀저장" onclick="javascript: InputCk(sbform);">

</form>

 </body>

</html>


#################################### 올렸으면 처리해야지
<%

' 엑셀 데이터 불러오기
Set xlsConn = Server.CreateObject("ADODB.connection")
If 넘어온파일확장자 = "xlsx" Then
xlsConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + 넘어온파일 + "; Extended Properties=""Excel 12.0;IMEX=1;"";"
ElseIf 넘어온파일확장자 = "xls"
xlsConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 넘어온파일 + "; Extended Properties=""Excel 8.0;IMEX=1;"";"
End If

xlsConn.Open xlsConnection
Set xlsRs = Server.CreateObject("ADODB.RecordSet")
SQL  = " Select * From [Sheet1$]"
xlsRs.Open SQL, xlsConn
' //엑셀 데이터 불러오기


' 엑셀 데이터 처리
i = 1
Do Until xlsRs.EOF

변수명 = xlsRs("엑셀시트 첫번째 이름")
' 처리하고 싶은 로직
Loop
' //엑셀 데이터 처리


xlsRs.close() : Set xlsRs = Nothing
xlsConn.close() : Set xlsConn = Nothing

%>


asp 소스


위에꺼는 파일 올리는 html

아래꺼는 액션

엑셀파일

시트이름은 Sheet1

컬럼 이름은 맞추어서 해야지 불러오기 편하다.