EXCELファイルのjsコードを読み込む


jsはEXCELファイルの実装コードを読み取り、比較が完了したので、自分でテストすることができます.
トップページには中国語の説明例がありますが、次の例では多くの人がテストすることができます.
コードは次のとおりです.
<script language="javascript" type="text/javascript"><!-- 
function readExcel() { 
var excelApp; 
var excelWorkBook; 
var excelSheet; 
try{ 
excelApp = new ActiveXObject("Excel.Application"); 
excelWorkBook = excelApp.Workbooks.open("C:\\XXX.xls"); 
excelSheet = oWB.ActiveSheet; //WorkSheets("sheet1") 
excelSheet.Cells(6,2).value;//cell   
excelSheet.usedrange.rows.count;//      
excelWorkBook.Worksheets.count;//  sheet    
excelSheet=null; 
excelWorkBook.close(); 
excelApp.Application.Quit(); 
excelApp=null; 
}catch(e){ 
if(excelSheet !=null || excelSheet!=undefined){ 
excelSheet =nul; 
} 
if(excelWorkBook != null || excelWorkBook!=undefined){ 
excelWorkBook.close(); 
} 
if(excelApp != null || excelApp!=undefined){ 
excelApp.Application.Quit(); 
excelApp=null; 
} 
} 
// --></script> 

コードは次のとおりです.
WebページでEXCELファイルを開く場合は、閉じるときにプロセスにEXCELがあります.EXEなので、閉じてから、このページをリフレッシュしなければなりません!
<script> 
function ReadExcel() 
{ 
var tempStr = ""; 
var filePath= document.all.upfile.value; 
var oXL = new ActiveXObject("Excel.application"); 
var oWB = oXL.Workbooks.open(filePath); 
oWB.worksheets(1).select(); 
var oSheet = oWB.ActiveSheet; 
try{ 
for(var i=2;i<46;i++) 
{ 
if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" ) 
break; 
var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value; 
tempStr+=(" "+oSheet.Cells(i,2).value+ 
" "+oSheet.Cells(i,3).value+ 
" "+oSheet.Cells(i,4).value+ 
" "+oSheet.Cells(i,5).value+ 
" "+oSheet.Cells(i,6).value+"
"); } }catch(e) { document.all.txtArea.value = tempStr; } document.all.txtArea.value = tempStr; oXL.Quit(); CollectGarbage(); } </script> <html> <input type="file" id="upfile" /><input type="button" onclick="ReadExcel();" value="read"> <br> <textarea id="txtArea" cols=50 rows=10></textarea> </html>

二、
js excelファイルの読み込み
コードは次のとおりです.
<script> 
function readThis(){ 
var tempStr = ""; 
var filePath= document.all.upfile.value; 
var oXL = new ActiveXObject("Excel.application"); 
var oWB = oXL.Workbooks.open(filePath); 
oWB.worksheets(1).select(); 
var oSheet = oWB.ActiveSheet; 
try{ 
for(var i=2;i<46;i++){ 
if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" ) 
break; 
var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value; 
tempStr+=(" "+oSheet.Cells(i,2).value+" "+oSheet.Cells(i,3).value+" "+oSheet.Cells(i,4).value+" "+oSheet.Cells(i,5).value+" "+oSheet.Cells(i,6).value+"
"); } } catch(e){ //alert(e); document.all.txtArea.value = tempStr; } document.all.txtArea.value = tempStr; oXL.Quit(); CollectGarbage(); } </script> <html> <input type="file" id="upfile" /> <input type="button" onclick="readThis();" value=" "><br> <textarea id="txtArea" cols=50 rows=10></textarea> </html>

三、
私はvs 2005プラットフォームでこのような機能を実現し、1つのボタンをクリックして一度に大量のexcelファイルデータをsqlserver 2005にインポートします.
私はajax技術を使って、フロントでjavascriptでexcelファイルを操作して、すべてのexcelファイルを循環して読み取って、1行ごとに1つの配列の中に入れてwebサービスを通じてバックグラウンドに伝わってc#言語で1行のデータをデータベースに挿入します.考えはたぶんそうだろう.
現在、機能は実装されており、具体的なコードは以下の通りです.
Javascriptで関数を定義し、excelファイルデータをループ読み出します.
コードは次のとおりです.
function readExcel() 
{ 
try 
{ 
var ExcelNum=new Array(); 
//      ,            
WebServiceExcel.deleteOldNumber(); 
var oXL = new ActiveXObject( "Excel.Application "); 
\\r_c_num[5]   excel      
var path=document.all.excelpath.value+ "\\ "+r_c_num[5] 
var oWB = oXL.Workbooks.open(path); 
\\  excel     sheet      sheet     
for(var x=1;x <=oWB.worksheets.count;x++) 
{ 
oWB.worksheets(x).select(); 
var oSheet =oWB.ActiveSheet; 
\\            excel      
for(var i=parseInt(r_c_num[6]);i <=parseInt(r_c_num[7]);i++) 
{ 
for(var j=parseInt(r_c_num[8]);j <=parseInt(r_c_num[9]);j++) 
{ 
if(typeof(oSheet.Cells(i,j).value)== "undefined ") 
{ 
ExcelNum[j-parseInt(r_c_num[8])+6]= " "; 
} 
else 
{ 
switch_letter(j); 
ExcelNum[j-parseInt(r_c_num[8])+6]=oSheet.Cells(i,j).value; 
} 
} 
//                   
WebServiceExcel.insert_From_Excel(ExcelNum); 
} 
} 
} 
} 
catch(err) 
{ 
alert( "   , "+err.message); 
} 
} 

これはフロントのキーコードにすぎません.
今の问题は、もしexcelファイルのデータが多すぎるならば、导入の过程はとても长い时间を待って、性能はとても悪くて、どのように改善するべきですか??数千行のデータを導くとだめで、時間が我慢できません.请高手赐教,谢谢了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
JavaScriptでExcelを結合します.Applicationローカルexcelファイルを読み込み、表に示す簡単な例
コードは次のとおりです.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<HTML> 
<HEAD> 
<TITLE> New Document </TITLE> 
<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
var excelFileName = "E:/project/eomstools/ShowTaskCodeWorkbook/test.xls"; 
var oWB; 
function showExcel(targetDIVID){ 
//objID   ID 
//               ActiveX 
// Start Excel and get Application object. 
var oXL=null; 
try{ 
oXL = new ActiveXObject("Excel.Application"); 
}catch(e){ 
alert(e.message); 
return ; 
} 
if (oXL == null){ 
alert("  Excel    ,               Microsoft Office Excel               !"); 
return; 
} 
try{ 
// Get a new workbook. 
oWB = oXL.Workbooks.Open(excelFileName); 
for (i = 1; i <= oWB.Sheets.Count; i++){ 
if (oWB.Sheets(i).name.lastIndexOf(" ") != -1){ 
showSheet(i); 
} 
} 
} 
catch (e){ 
alert(e.message); 
} 
oWB.Close();   // close     ,        。 
oWB = null; 
oXL = null; 
} 
function showSheet(sheetNO){ 
var oSheet = oWB.Sheets(sheetNO); 
document.write("<table border=1>"); 
for (i = 1; i < oSheet.UsedRange.Rows.Count; i++){ 
document.write("<tr>"); 
for (j = 1; j < oSheet.UsedRange.Columns.Count; j++){ 
value = oSheet.Cells(i, j).Value; 
if (value == undefined){ 
value = " "; 
} 
document.write(i == 1 ? "<th nowrap=true><b>" : "<td>"); 
document.write(value); 
document.write(i == 1 ? "</b></th>" : "</td>"); 
} 
document.write("</tr>"); 
} 
document.write("</table>"); 
oSheet = null; 
} 
//--> 
</SCRIPT> 
</HEAD> 
<BODY onLoad="showExcel();"> 
</BODY> 
</HTML> 

jsはEXCELファイルの実装コードを読み取り、比較が完了したので、自分でテストすることができます.
JSでexcelを読み込む例
コードは次のとおりです.
<% 
'' 
'********************************************************* 
'   :  excel                       
'   : 
'   : 
'********************************************************* 
Function GetExcel() 
Dim conn 
Dim StrConn 
Dim rs 
Dim Sql 
file="" 
Set conn=Server.CreateObject("ADODB.Connection") 
StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("EXCEL_DATA.xls") 
''StrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=dd.xls;Extended Properties=Excel 8.0" 
conn.Open StrConn 
Set rs = Server.CreateObject("ADODB.Recordset") 
Sql="select * from [Sheet1$]" 
rs.Open Sql,conn,2,2 
''  excel      ,            
for i=0 to rs.Fields.Count-1 
FILE_HEAD=FILE_HEAD&rs(i).Name 
next 
''response.write FILE_HEAD 
IF trim(FILE_HEAD)<>"                              " THEN 
RESPONSE.WRITE "<SCRIPT LANGUAGE='JAVASCRIPT'>alert('EXCEL              !!')</SCRIPT>" 
exit Function 
END IF 
''  excel     
do while Not rs.EOF 
''      INSERT oracle    
for i=0 to rs.Fields.Count-1 
EDITION=rs(0) 
FILE_CODE=rs(2)+rs(3)+rs(4)+rs(5) 
FILE_NAME=rs(9) 
KIND1_DESC=rs(6) 
KIND2_DESC=rs(7) 
KIND3_DESC=rs(8) 
KIND4_DESC=rs(9) 
SAVE_YEAR=rs(10) 
FILE_UNIT=rs(1) 
COM_FILE_CODE=rs(11) 
''============================================== 
CHECED_SQL="Select nvl(FILE_CASE,'') FILE_CASE FROM ODM67 where EDITION='"&TRIM(EDITION)&"' and FILE_CODE='"&TRIM(FILE_CODE)&"' " 
If mobjDB.OpenSQL(CHECED_SQL) Then 
If mobjDB.IsEmpty Then 
FILE_CASE="0001" 
CASE_DESC="  " 
INS_SQL="" 
INS_SQL=INS_SQL & " INSERT INTO ODM67(" & VBCRLF 
INS_SQL=INS_SQL & " EDITION,FILE_CODE,FILE_CASE," & VBCRLF 
INS_SQL=INS_SQL & " CASE_DESC,CRT_USER,CRT_DATE," & VBCRLF 
INS_SQL=INS_SQL & " CRT_TIME,MDF_USER,MDF_DATE,MDF_TIME)" & VBCRLF 
INS_SQL=INS_SQL & " VALUES(" & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(EDITION)&"','"&TRIM(FILE_CODE)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(FILE_CASE)&"','"&TRIM(CASE_DESC)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(SESSION("USER_ID"))&"','"&TRIM(TODAY)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(NOWTIME)&"','"&TRIM(SESSION("USER_ID"))&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(TODAY)&"','"&TRIM(NOWTIME)&"')" 
CALL mobjDB.ExecSQL(INS_SQL) 
End If 
End If 
''============================================== 
INS_SQL="" 
INS_SQL=INS_SQL & " INSERT INTO ODM61( " & VBCRLF 
INS_SQL=INS_SQL & " EDITION,FILE_CODE,FILE_NAME,KIND1_DESC," & VBCRLF 
INS_SQL=INS_SQL & " KIND2_DESC,KIND3_DESC,KIND4_DESC,SAVE_YEAR," & VBCRLF 
INS_SQL=INS_SQL & " FILE_UNIT,COM_FILE_CODE,CRT_USER,CRT_DATE," & VBCRLF 
INS_SQL=INS_SQL & " CRT_TIME,MDF_USER,MDF_DATE,MDF_TIME)" & VBCRLF 
INS_SQL=INS_SQL & " VALUES(" & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(EDITION)&"','"&TRIM(FILE_CODE)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(FILE_NAME)&"','"&TRIM(KIND1_DESC)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(KIND2_DESC)&"','"&TRIM(KIND3_DESC)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(KIND4_DESC)&"','"&TRIM(SAVE_YEAR)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(FILE_UNIT)&"','"&TRIM(COM_FILE_CODE)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(SESSION("USER_ID"))&"','"&TRIM(TODAY)&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(NOWTIME)&"','"&TRIM(SESSION("USER_ID"))&"'," & VBCRLF 
INS_SQL=INS_SQL & " '"&TRIM(TODAY)&"','"&TRIM(NOWTIME)&"')" 
''RESPONSE.WRITE INS_SQL& "<BR>" 
IF mobjDB.ExecSQL(INS_SQL) THEN 
InCount=InCount+1 
ELSE 
NoCount=NoCount+1 
file=file&TODAY&" "&NOWTIME&" "&EDITION&" "&FILE_CODE & VBCRLF 
END IF 
exit for 
next 
rs.MoveNext 
Loop 
rs.close 
set rs=nothing 
Conn.close 
set StrConn=nothing 
if file<>"" then 
CALL CreateFolder() 
call SetFile(file) 
strpath=server.mappath("EXCEL_DATA.xls") 
call DeleteFolder(strpath) 
file="" 
end if 
End Function 
'********************************************************* 
'   :          ,        ,         
'   : file:       
'   : 
'********************************************************* 
Function SetFile(file) 
file_path="C:\LOG\OD60err.log" 
set fstemp=server.CreateObject("Scripting.FileSystemObject") 
IF (fstemp.FileExists(file_path)) THEN 
ELSE 
set filetemp=fstemp.CreateTextFile(file_path,true) 
filetemp.writeLine "        " 
filetemp.close 
END IF 
''        OpenTextFile 
set filetemp=fstemp.OpenTextFile(file_path,8,true) 
filetemp.writeLine file 
filetemp.close 
set filetemp=Nothing 
set fstemp=Nothing 
End Function 
'********************************************************* 
'   :           ,         
'   : 
'   : 
'********************************************************* 
Function CreateFolder() 
Dim fso, f 
folder="c:\LOG" 
Set fso = CreateObject("Scripting.FileSystemObject") 
IF fso.FolderExists(folder) THEN 
ELSE 
Set f = fso.CreateFolder(folder) 
CreateFolderDemo = f.Path 
END IF 
End Function 
'********************************************************* 
'   :       , 
'   :            
'   : 
'********************************************************* 
Function DeleteFolder(filepath) 
Dim fso, f 
folder="EXCEL_DATA.xls" 
Set fso = CreateObject("Scripting.FileSystemObject") 
''response.write fso.FileExists(filepath) 
IF fso.FileExists(filepath) THEN 
fso.DeleteFile filepath 
END IF 
End Function 
%> 

     : 
<script> 
function readThis(){ 
var tempStr = ""; 
var filePath= document.all.upfile.value; 
var oXL = new ActiveXObject("Excel.application"); 
var oWB = oXL.Workbooks.open(filePath); 
oWB.worksheets(1).select(); 
var oSheet = oWB.ActiveSheet; 
try{ 
for(var i=2;i<46;i++){ 
if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" ) 
break; 
var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value; 
tempStr+=(" "+oSheet.Cells(i,2).value+ 
" "+oSheet.Cells(i,3).value+ 
" "+oSheet.Cells(i,4).value+ 
" "+oSheet.Cells(i,5).value+ 
" "+oSheet.Cells(i,6).value+"
"); } }catch(e){ //alert(e); document.all.txtArea.value = tempStr; } document.all.txtArea.value = tempStr; oXL.Quit(); CollectGarbage(); } </script> <html> <input type="file" id="upfile" /><input type="button" onclick="readThis();" value=" "> <br> <textarea id="txtArea" cols=50 rows=10></textarea> </html>