Java,J2EE,Weblogic,Oracle

java项目随笔
随笔 - 90, 文章 - 6, 评论 - 61, 引用 - 0
数据加载中……

JavaScript 操作excel 或word

/////////////////////////////////////////// Parameter ///////////////////////////////////
var winSelector = 0;
var previousOpenedWindow   = 0;

String.prototype.StrLenGB2312 = function(){
    var liLen = 0;
 for(liLoop = 0; liLoop< this.length;liLoop++){
   var c = this.charAt(liLoop);
     if ((escape(c)).length == (c.length) * 6 )
      liLen += 2;
     else
       liLen ++;
   }
   return liLen;
}

String.prototype.StrLenUTF8 = function(){
 var liLen = 0;
 for(liLoop = 0; liLoop< this.length;liLoop++){
   var c = this.charAt(liLoop);
     if ((escape(c)).length == (c.length) * 6 )
      liLen += 3;
     else
       liLen ++;
   }
   return liLen;
}
////////////////////////////////////////////Business Function ////////////////////////
//////////////////////////////////////////////////
//  Attachment
//////////////////////////////////////////////////
function updateAttachment(formName, attachment, attachment_id, attachmentNameMessage, tableCode, srcID, originalAttachmentName) {
    var form = document.forms[formName]
    var attachmentIDs = form.elements[attachment];
 openSelector( servletPath + 'uploadFile?subCmd=requestUploadFile&formName=' + formName + '&tableCode=' + tableCode + '&srcID=' + srcID + '&attachment=' + attachment + '&attachment_id=' + attachment_id + '&attachmentNameMessage=' + attachmentNameMessage + '&originalAttachment=' + originalAttachmentName + '&originalAttachmentIDs=' + attachmentIDs.value, 'updateAttachment', 620, 400)
}


/////////////////////////////////////////////  Basic Funciton /////////////////////////
function openSelector(url, title, width, height) {
    if(!checkSelector()) return;
    winSelector = window.open(url, title,"width="+width+",height="+height+","+"status=0,scrollbars=1,resizable=1,left=0,top=0,dependent=1");
    winSelector.focus();
    return winSelector;
}

function checkSelector() {
    if(winSelector && !winSelector.closed) {
        winSelector.focus();
        return 0;
    }
    return 1;
}
var dateField;
function selectDate(pDateFormName, pDateFieldName){
    var form = document.forms[pDateFormName];
    dateField = form.elements[pDateFieldName];
    openSelector(jsPath + 'chooseDate.html', 'chooseDate', 300,275);
}
function setDateValue(dateValue){
 dateField.value = dateValue;
}
function gotoPage_1(formName,purposePages){
 //alert("1");
 //var form = document.forms[formName]
 //var tt = 'document.' + formName + '.purpoasePage.value = ' + purposePages;
 //eval(tt);
 //var ss = 'document.' + formName + '.submit()';
 //eval(ss);
 //var form = document.forms[formName];
 //alert("2");
 //var purpoasePage = form.elements['purpoasePage'];
 //purposePage.value = purposePages;
 //alert("3");
 //form.submit();
}

function openWin(url, title, width, height) {
 window.open(url, title,"width="+width+",height="+height+",status=no,scrollbars=1,resizable=1");
}

function selectEmployee(formName, fieldName, hiddenFieldName, departmentFieldName) {
    var form = document.forms[formName]
 var appendString = "";
 if( departmentFieldName!=null ) {
        var departmentField = form.elements[departmentFieldName];
        if( departmentField.value!='' ) {
            appendString = '&departmentId='+departmentField.value;
        }else{
            appendString = '&departmentId=-1';
        }
 }else{
     appendString = '&departmentID=-1';
 }
    openSelector( servletPath + 'employee?subCmd=query&formName=' + formName + '&fieldName=' + fieldName +'&hiddenFieldName='+hiddenFieldName +appendString +'&isSelectHuaweiEmployee=false', 'selectEmployee', 720, 420);
}

/*
* 判断是否数字
*/
function isCharNum(obj) {

 var testString = obj.value;
 for(var i = 0; i < testString.length; i++){
  var character = testString.charCodeAt(i);    
  if(character > 57 || character < 48){
   return false;
  }
 }
 return true;
}


/**
 *
 * 判断是不是有效的英文字母和数字
 */

function checkIsLetterNumber(str) {
    //如果为空则通过检验
    if (str == "" || str.length == 0) {
        return true;
    }

    //正则表达式
    var pattern = /[^a-zA-Z0-9\s]/g;
    if (pattern.test(str)) {
        return false;
    }
    return true;
}


/*** 
 * 检查配发新卡合法性。 五个级别的渠道分卡时都调用了这个方法。 linnngo 20060609
 */
 
function checkCardLength(smallCardNoLength,greatCardNoLength){
 //开始卡号位数检查
 if(smallCardNoLength == 0){
  alert("请输入开始卡号!");
  return;
 }
 if(smallCardNoLength == 19 || smallCardNoLength == 10){
  //表示可以继续
 } else {
  alert("输入的卡号位数不正确,必须是19或10位!你输入的开始卡号是" + smallCardNoLength + "位!");
  return;
 }
 
 //结束卡号位数检查
 if(greatCardNoLength == 0){
  alert("请输入结束卡号!");
  return;
 } 
 if(greatCardNoLength == 19 || greatCardNoLength == 10){
  //表示可以继续
 }else{
  alert("输入的卡号位数不正确,必须是19或10位!你输入的结束卡号是" + greatCardNoLength + "位!");
  return;
 }
 
 if(smallCardNoLength != greatCardNoLength){
  alert("输入的开始卡号和结束卡号长度不一样!");
  return;
 }

 //开始卡号是否数字检查
 if(isCharNum(document.allotCardForm.smallCardNo) && isCharNum(document.allotCardForm.greatCardNo)){
  if(confirm("确定提交?")){
   document.allotCardForm.submit();
  }
 }else {
  alert("输入的卡号不正确,卡号只能是数字!");
 }
}

function tableMouseOver(Obj){
 Obj.style.backgroundColor='#f2f2f2';
}
function tableMouseOut(Obj){
 Obj.style.backgroundColor='';
}
 
 //指定页面区域内容导入Excel
 function AllAreaExcel()
 {
  var oXL = new ActiveXObject("Excel.Application");
  var oWB = oXL.Workbooks.Add();
  var oSheet = oWB.ActiveSheet; 
  var sel=document.body.createTextRange();
  sel.moveToElementText(dataTableId);
  sel.select();
  sel.execCommand("Copy");
  oSheet.Paste();
  oXL.Visible = true;
 }
 //指定页面区域“单元格”内容导入Excel
 function CellAreaExcel()
 {
  var oXL = new ActiveXObject("Excel.Application");
  var oWB = oXL.Workbooks.Add();
  var oSheet = oWB.ActiveSheet;
  var Lenr = dataTableId.rows.length;
  for (i=0,o=0;i<Lenr;i++,o++)
  {
 var trid = dataTableId.rows(i).id;
 if(trid)
 {
  o--;
  continue;
 }
 var Lenc = dataTableId.rows(i).cells.length;
 for (j=0;j<Lenc;j++)
 {
  if(j==0)
  {
   var tmpText = dataTableId.rows(i).cells(j).innerText;
   var position = tmpText.indexOf("\n");
   if(position > -1)
   {
    tmpText = tmpText.substring(0,position);
   }
   oSheet.Cells(o+1,j+1).value = tmpText;
  }
  else
  {
    oSheet.Cells(o+1,j+1).value = dataTableId.rows(i).cells(j).innerText;
   }
 }
  }
  oXL.Visible = true;
 }

 //指定页面区域内容导入Word
 function AllAreaWord()
 {
  var oWD = new ActiveXObject("Word.Application");
  var oDC = oWD.Documents.Add("",0,1);
  var oRange =oDC.Range(0,1);
  var sel = document.body.createTextRange();
  sel.moveToElementText(dataTableId);
  sel.select();
  sel.execCommand("Copy");
  oRange.Paste();
  oWD.Application.Visible = true;
 }

posted on 2007-07-16 17:55 龚椿深 阅读(483) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: