Where The Streets Have No Name

엑셀데이터 임포트 본문

Developement/RIA

엑셀데이터 임포트

highheat 2006. 7. 25. 11:47
<HTML>
<HEAD>
<SCRIPT language="JavaScript" src="embedControl.js"></SCRIPT>
<script language="javascript">
//global variables
file_name = "";
var THeader="no:INT(7),empno:STRING(7),entrydt:DATE(8),salary:DECIMAL(10.2),url:URL(100)";

function fncClick(){
 var fileExcel = document.getElementsByName("file_excel")[0];
 alert(fileExcel.value);
 file_name = fileExcel.value;
}
function fncLoadExcel(){
 //파일명 설정
 file_name = document.getElementsByName("file_excel")[0].value;

 var oExcel, oBook, oSheet, oRange;                                                            
    oExcel = new ActiveXObject("Excel.Application");                               
    oExcel.Visible = false;                                                         
    oBook = oExcel.Workbooks.Open(file_name);
   
    oSheet = oBook.ActiveSheet;
    //alert(oSheet.Rows.Count+","+oSheet.Columns.Count);
    //alert(oSheet.Cells(1,10));
   
    //data가 존재하는 부분 확인
    var i; //행
    for(i = 1;i <= oSheet.Columns.Count;i++){  
     if( String(oSheet.Cells(i,1)) == "undefined" ){
      alert(i);
      break;
     }
    }
   
    tb_DataSet.SetDataHeader(THeader);
    //타이틀행은 생략하고 입력
    for(var j = 2;j < i;j++){
     tb_DataSet.AddRow();
     tb_DataSet.NameValue(tb_DataSet.RowPosition,"no") = String(oSheet.Cells(j,1));
     tb_DataSet.NameValue(tb_DataSet.RowPosition,"empno") = String(oSheet.Cells(j,2));
     tb_DataSet.NameValue(tb_DataSet.RowPosition,"entrydt") = String(oSheet.Cells(j,3));
     tb_DataSet.NameValue(tb_DataSet.RowPosition,"salary") = String(oSheet.Cells(j,4));
     tb_DataSet.NameValue(tb_DataSet.RowPosition,"url") = String(oSheet.Cells(j,5));   
    }
   
    oExcel.Application.Quit();  
}
</script>
<script language=JavaScript for=tb_DataSet event=onDataError(row,colid)>
 alert("ErrorCode : " + tb_DataSet.ErrorCode + "" + "ErrorMsg  : " + tb_DataSet.ErrorMsg);
</script>
<object classid=CLSID:3267EA0D-B5D8-11D2-A4F9-00608CEBEE49 id=tb_DataSet>
</object>
<!----- 화면 Titile  ----->
<TITLE>excel import</TITLE>

</HEAD>
<body>
<input type="file" name="file_excel">
<input type="button" OnClick="fncClick()" value="test">
<input type="button" OnClick="fncLoadExcel()" value="load excel">
<input type=button value="Set Header" onClick="tb_DataSet.SetDataHeader(THeader)">
<input type=button value="Text" onClick="alert(tb_DataSet.Text)">
<comment id="__NOSCRIPT_ID__"><object classid=CLSID:1F57AEAD-DB12-11D2-A4F9-00608CEBEE49 height=320 width=456>
  <param name=DataID  value=tb_DataSet> 
  <param name=Format  value='
   <C>ID=no  name="No"   width=100</C>
   <C>ID=empno  name="Empno"  width=100</C>
   <C>ID=entrydt name="EntryDate" width=100</C>
   <C>ID=salary name="Salary"  width=100</C>
   <C>ID=url    name="Url"         width=100</C>'>
 </object></comment><SCRIPT>__ShowEmbedObject(__NOSCRIPT_ID__);</SCRIPT>
</BODY>
</HTML>