`

js 操作xls 新建,判断,之java 樱花无罪

 
阅读更多

         最近做了一个xls 文件导入,导入之前要进行文件格式判断,前面的技术员是提交后台进行判断,我很懒,直接用了js 处理,不知道是好是坏!期 待各位大侠建议

           有什么沟通请联系   QQ:962589149

               在此附送个人js代码,期待指教!

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">

String.prototype.trim = function() {
  var str = this,
  whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
  for (var i = 0,len = str.length; i < len; i++) {
    if (whitespace.indexOf(str.charAt(i)) === -1) {
      str = str.substring(i);
      break;
    }
  }
  for (i = str.length - 1; i >= 0; i--) {
    if (whitespace.indexOf(str.charAt(i)) === -1) {
      str = str.substring(0, i + 1);
      break;
    }
  }
  return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
function MakeExcel() {
 alert("begin");
 var i, j, n;
 try {
   var xls = new ActiveXObject("Excel.Application");
 }
 catch(e) {
   alert( "要生成该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须允许执行控件。请点击【帮助】了解浏览器设置方法!");
  return "";
 }
 xls.visible =true; // 设置excel为可见
 var xlBook = xls.Workbooks.Add;
 var xlsheet = xlBook.Worksheets(1);
 xlsheet.Cells(2,1).Value = "卡号";
 xlsheet.Cells(2,2).Value = "密码";
 xlsheet.Cells(2,3).Value = "计费方式";
 xlsheet.Cells(2,4).Value = "有效天数";
 xlsheet.Cells(2,5).Value = "金额";
 xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
 xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="发卡记录";
 xlBook.SaveAs("C:\\TEST.XLS");
 // 用 Application 对象用 Quit 方法关闭 Excel。
 xlBook.Application.Quit();
 xls=null;
 xlBook=null;
 xlsheet=null;
}


function ReadExcel()
{
  var special=new Array("证号","姓名","性别","文化程度","工作单位");//特种格式
  var notspecial=new Array("证号","姓名","身份证号码","性别","文化程度");//非特种
  var strs= new Array(); //定义一数组
     var tempStr = "";
     var filePath="F:\\参考\\CMS-GZAJ\\CMS系统2012-05-22更改需求\\生产经营单位主要负责人和安全管理人员名册.xls";
     var oXL = new ActiveXObject("Excel.application");
     var oWB = oXL.Workbooks.open(filePath);
     oWB.worksheets(1).select();
     var oSheet = oWB.ActiveSheet;
     try{
      for(var i=1;i<2;i++)
      {
       if(oSheet.Cells(i,1).value =="null" || oSheet.Cells(i,2).value =="null" )
        break;
       var a = oSheet.Cells(i,1).value.toString()=="undefined"?"":oSheet.Cells(i,1).value;
       tempStr+=(oSheet.Cells(i,1).value.trim()+
        ","+oSheet.Cells(i,2).value.trim()+
        ","+oSheet.Cells(i,3).value.trim()+
        ","+oSheet.Cells(i,4).value.trim()+
        ","+oSheet.Cells(i,5).value.trim());
      }
     }catch(e)
     {
          document.all.txtArea.value = tempStr;
     }
  alert(tempStr);
 tempStr= tempStr.trim();
  alert(tempStr);
  strs=tempStr.split(","); //字符分割
 if(strs.toString() ==special.toString())
 {
  alert("特种");
 }
 if(strs.toString() ==notspecial.toString())
 {
  alert("非特种");
 }

     document.all.txtArea.value = tempStr;
     oXL.Quit();
    // CollectGarbage();
}

    </script>
 
</head>

<body>
<input type="button" value="保存" onclick="MakeExcel();" />
<input type="button" value="读取" onclick="ReadExcel();" />
<textarea name="txtArea"  cols="150" rows="10">

</textarea>
</body>
</html>

SQL                                                需要修改前20条数据

SET   ROWCOUNT   20
update  t_corporation_history set  lastState=1  where corpType=11
SET   ROWCOUNT   0

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics