excel 处理 by JS

js 处理 excel

<html>
<script type = "text/javascript">  
    function init() {  
        //alert("Hello World!!!");  
    }  


    </script>  
<body onload=init()> 
<script type = "text/javascript"> 
var oXL = new ActiveXObject("Excel.Application");  
var oWB = oXL.Workbooks.open("D:/excel_JS/es.xlsx"); 
oWB.worksheets(1).select(); 
var oSheet1 = oWB.ActiveSheet; 
oWB.worksheets(2).select(); 
var oSheet2 = oWB.ActiveSheet; 


var sheet1_row =oWB.Worksheets(1).UsedRange.Cells.Rows.Count; 
var sheet1_col =oWB.Worksheets(1).UsedRange.Columns.Count; 
 
var sheet2_row =oWB.Worksheets(2).UsedRange.Cells.Rows.Count; 
var sheet2_col =oWB.Worksheets(2).UsedRange.Columns.Count; 
 

try { 
	for (var j=1;j<=sheet2_row;j++) { 

		for(var x = 1; x <= sheet1_row; x++) {
			if (oSheet1.Cells(x,1).value == oSheet2.Cells(j,1).value) {
				document.write(oSheet1.Cells(x,2).value + " ");
				document.write("<br/>"); 
			}

		}

	} 
} 
catch(e) 
{ 
    oWB.close(); 
} 
oWB.close();
   </script> 

</body>
</html>

2

<html>
<script type = "text/javascript">  
    function init() {  
        //alert("Hello World!!!");  
    }  
function deal() {
	

var oXL = new ActiveXObject("Excel.Application");  
var oWB = oXL.Workbooks.open(document .getElementById("ifile").value); 
oWB.worksheets(1).select(); 
var oSheet1 = oWB.ActiveSheet; 
oWB.worksheets(2).select(); 
var oSheet2 = oWB.ActiveSheet; 


var sheet1_row =oWB.Worksheets(1).UsedRange.Cells.Rows.Count; 
var sheet1_col =oWB.Worksheets(1).UsedRange.Columns.Count; 
 
var sheet2_row =oWB.Worksheets(2).UsedRange.Cells.Rows.Count; 
var sheet2_col =oWB.Worksheets(2).UsedRange.Columns.Count; 
 

try { 
	for (var j=1;j<=sheet2_row;j++) { 

		for(var x = 1; x <= sheet1_row; x++) {
			if (oSheet1.Cells(x,1).value == oSheet2.Cells(j,1).value) {
				document.write(oSheet1.Cells(x,2).value + " ");
				document.write("<br/>"); 
			}

		}

	} 
} 
catch(e) 
{ 
    oWB.close(); 
} 
oWB.close();




}

    </script>  
<body onload=init()> 

请选择需要处理的文件: <input id  = ifile type="file">

<input onclick = deal(); type = button value=处理>
<br/>
<br/>

<script type = "text/javascript"> 

   </script> 
<div id = cc></div>

</body>
</html>

 3.html

<html>  
<script type = "text/javascript">    
//this function is owned by Sam Song <[email protected]> 12/23/2014 


function deal() {  

  
var oXL = new ActiveXObject("Excel.Application");    
var oWB = oXL.Workbooks.open(document.getElementById("ifile").value);   
oWB.worksheets(1).select();   
var oSheet1 = oWB.ActiveSheet;   
oWB.worksheets(2).select();   
var oSheet2 = oWB.ActiveSheet;   
  
  
var sheet1_row =oWB.Worksheets(1).UsedRange.Cells.Rows.Count;   
var sheet1_col =oWB.Worksheets(1).UsedRange.Columns.Count;   
   
var sheet2_row =oWB.Worksheets(2).UsedRange.Cells.Rows.Count;   
var sheet2_col =oWB.Worksheets(2).UsedRange.Columns.Count;   
   var counter=0;
  	
	document.write("Results:");document.write("<br/>");
	document.write("-------------------------------");
		document.write("<br/>");
try {   
    for (var j=1;j<=sheet2_row;j++) {   
  
        for(var x = 1; x <= sheet1_row; x++) {  
            if (oSheet1.Cells(x,1).value == oSheet2.Cells(j,1).value) {  
                document.write(oSheet1.Cells(x,2).value + " ");  
                document.write("<br/>");   
				counter++;
            }  
  
        }  
  
    }   
	counter--;
	document.write("<br/>");
	document.write("-------------------------------");
		document.write("<br/>");
	document.write("Total:" + counter);
	document.write("<br/>");
}   
catch(e)   
{   alert(e.toString());
    oWB.close();   
	
}   
oWB.close();  
  
  
  
}  
  
    </script>    
<body>   
  
Please select the Excel file: <input id  = ifile type="file">  <br> 
<label style="font-size:13px">
Note: <br>

1. This tool can query matreials by sequence numbers. <br>
2. The first sheet is data source, the sequence number should be in first column. <br>
3. The second sheet is query condition, the sequence number should be in first column. <br>
 
</label>
 <br>

<input onclick = deal() type = button value=Query>  
<br/>  
<br/>  
<label style="font-size:14px">
Following below instructions to enable ActiveX in your computer:<br/> 
1. To help protect your security, Interner Explorer has restricted this webpage from running scripts 
   <br> 
   &nbsp;&nbsp;&nbsp;or ActiveX controls that could access our computer. Click here for options...<br/> 
2. Click yellow warning bar<br/> 
3. Allow Blocked Content...<br/> 
4. Click Yes<br/> 
5. After browse excel file and click Query button. Below warning message will popup.<br/> 
&nbsp;&nbsp;&nbsp;An ActiveX control on this page might be unsafe to interact with other parts of the page. <br/> 
&nbsp;&nbsp;&nbsp;Do you want to allow this interaction?<br/> 
6. Click Yes
</label>
<br/> 
</body>  
</html> 

猜你喜欢

转载自samsongbest.iteye.com/blog/2168484
今日推荐