输出Word Excel

上一篇 / 下一篇  2007-06-15 15:13:10 / 个人分类:java

 <TD class=P ōnmouseover=MO() ōnclick="exportExcelInfo('<%=goods_sales_borough_report%>')" ōnmouseout=MU() noWrap>
                 <IMG alt='' hspace=5 src="../image/excel.jpg" align=absMiddle border=0><%=excel_data%></TD>
            <TD class=LL>|</TD>
            <TD class=P ōnmouseover=MO() ōnclick="exportWordInfo('<%=goods_sales_borough_report%>','1')" ōnmouseout=MU() noWrap>
                 <IMG alt='' hspace=5 src="../image/word.jpg" align=absMiddle border=0><%=word_data%></TD>

 

 

 

 

 

 

function resize_rect()
 {
          try{
            var o = document.getElementById("rect");
            o.style.width = document.body.clientWidth-2 + "px";
            o.style.height =document.body.clientHeight-60 + "px";
          }catch(e)
          {}
  }

  window.onresize = resize_rect;

function checkType_Num(obj)
{
       if((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||event.keyCode==8||event.keyCode==110||event.keyCode==46||event.keyCode==190)
       {
    event.returnValue=true;
       }
  else
    event.returnValue=false;

}

function display_editCustomer(ID){
 reValue=window.open("../cilent/editcilent.jsp?id="+ID, "editcilent", "height=600,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
}

function display_viewCompany(ID){
  reValue=window.open("../system/company_view.jsp?companyid="+ID, "viewCompany", "height=700,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
}

function display_editMaterial(ID){
  reValue=window.open("../material/editMaterial.jsp?materialID="+ID, "editMaterial", "height=700,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
}

 //指定页面区域“单元格”内容导入Excel
 function exportExcel(titleName)
 {
   try{
  var ōXL = new ActiveXObject("Excel.Application");
  var ōWB = oXL.Workbooks.Add();
  var ōSheet = oWB.ActiveSheet;
  var PrintA = document.all("tableRpt");
  var Lenr = PrintA.rows.length;
  var colSite =  Math.round(PrintA.rows(0).cells.length / 2);
  oSheet.Cells(1,colSite).value=titleName;
  oSheet.Cells(1,colSite).Font.Bold =1;
  oSheet.Cells(1,colSite).Font.Size=12;

  for (i=1;i<Lenr;i++)
  {
   var Lenc = PrintA.rows(i-1).cells.length;
   for (j=0;j<Lenc;j++)
   {
    oSheet.Cells(i+1,j+1).value = PrintA.rows(i-1).cells(j).innerText;
    oSheet.Cells(i+1,j+1).Font.Size=10;
    if(i==1)
    {
      oSheet.Cells(i+1,j+1).Font.Bold =1;
    }
   }

  }
  oXL.Visible = true;
  ōXL = null;
  }catch(e){}
  finally{
        idTmr  =  window.setInterval("Cleanup();",1);
  }
}

function  Cleanup()  {
   window.clearInterval(idTmr);
   CollectGarbage();
}

function exportWord(titleName,calcIndex)        //calcIndex 计算列开始序号
{
  try{
      var PrintA = document.all("tableRpt");
      var row_count = PrintA.rows.length-1;
      var col_count = PrintA.rows(0).cells.length;

      var WordApp=new ActiveXObject("Word.Application");    //得到WORD对象

      var wdCharacter=1;
      var wdOrientLandscape = 1;
      var myDoc=WordApp.Documents.Add();

      WordApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
      WordApp.Selection.Font.Size=12;
      WordApp.Selection.Font.Bold=1;
      WordApp.Selection.TypeText(titleName);
      WordApp.Selection.Paragraphs(1).Alignment=1;
      WordApp.Selection.MoveRight(1);
      WordApp.Selection.TypeParagraph();
      WordApp.Selection.TypeParagraph();
      WordApp.Selection.Font.Bold=0;

     var myTable=myDoc.Tables.Add (WordApp.Selection.Range, row_count,col_count)
     var TableRange;  //以下为给表格中的单元格赋值

     for (i =0;i<row_count;i++)
     {
       for (n =0;n<col_count ;n++)
       {
          with (myTable.Cell(i+1,n+1).Range)
          {
            font.Size = 10;
            if(i==0)
            {
               font.Bold =1;
            }
            if(n>=calcIndex)
              ParagraphFormat.Alignment=2;
            else
              ParagraphFormat.Alignment=0;
            if(i==0)
              ParagraphFormat.Alignment=1;

            InsertAfter(PrintA.rows(i).cells(n).innerText);
          }
        }
      }

      row_count = 0;
      col_count = 0
      WordApp.Application.Visible=true;
  }catch(e){}
      finally{
         idTmr  =  window.setInterval("Cleanup();",1);
      }
}

function searchCustomer(contactID)
{
     var cusID=document.all("customerID").value
     var url = '../invoice/getcustomer';
     var pars = 'customerID=' + cusID+"&contactID="+contactID+"&t="+Math.random();
     var bankAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: fillCustomerInfo});
}


function choseCode(code,customerID,payment,saleStaff,contactType,paymentTerm,invoiceDeliver)
{
  parent.opener.document.all("contacter").length=0;
  parent.opener.document.all("customerID").value=customerID;
  parent.opener.document.all("customerInfo").value=document.all(code).value;
  if(parent.opener.document.all("paymentMethodID"))
     parent.opener.document.all("paymentMethodID").value=payment;
  if(parent.opener.document.all("salesStaffID"))
     parent.opener.document.all("salesStaffID").value=saleStaff;
  if(parent.opener.document.all("paymentTerms"))
     parent.opener.document.all("paymentTerms").value=paymentTerm;
  if(parent.opener.document.all("invoiceDeliver"))
     parent.opener.document.all("invoiceDeliver").value=invoiceDeliver;
  var url = '../invoice/getcontacter';
  var pars = "customerID=" + customerID+"&contactType="+contactType+"&t="+Math.random() ;
  var bankAjax = new Ajax.Request(url,{method: 'get', parameters: pars, onComplete: fillContact});

}

function fillContact(requestObj)
{
  try{
      var resultf=requestObj.responseXML.getElementsByTagName("firstName");
      var resultl=requestObj.responseXML.getElementsByTagName("lastName");
      var resulti=requestObj.responseXML.getElementsByTagName("contactID");
    for(i=0;i<=resultf.length-1;i++)
    {
      firstName=resultf[i].firstChild==null?"":resultf[i].firstChild.nodeValue;
      lastName=resultl[i].firstChild==null?"":resultl[i].firstChild.nodeValue;
      contactID=resulti[i].firstChild==null?"":resulti[i].firstChild.nodeValue;
      parent.opener.fillContactOption(contactID,firstName+lastName);
    }
  }catch(e){}
  finally{
     window.close();
  }
}

 

 function exportExcelInfo(titleName)
 {
   try{
  var ōXL = new ActiveXObject("Excel.Application");
  var ōWB = oXL.Workbooks.Add();
  var ōSheet = oWB.ActiveSheet;
  var PrintA = document.all("tableRpt");
  var Lenr = PrintA.rows.length;
  var colSite =  Math.round(PrintA.rows(0).cells.length / 2);
  oSheet.Cells(1,colSite).value=titleName;
  oSheet.Cells(1,colSite).Font.Bold =1;
  oSheet.Cells(1,colSite).Font.Size=12;
   var info=document.all("info").innerHTML
    oSheet.Cells(2,1).value=info.replace(/&nbsp;/g,'  ');
    oSheet.Cells(2,1).Font.Bold =0;
    oSheet.Cells(2,1).Font.Size=10;
    oSheet.Range('A2:Z2').Select();
    oXL.Selection.Merge();
    oXL.Selection.HorizontalAlignment = -4131;

  var k=0;
  for (i=2;i<Lenr+1;i++,k++)
  {
   var Lenc = PrintA.rows(k).cells.length;
   for (j=0;j<Lenc;j++)
   {
    oSheet.Cells(i+1,j+1).value = PrintA.rows(k).cells(j).innerText;
    oSheet.Cells(i+1,j+1).Font.Size=10;
    if(i==1)
    {
      oSheet.Cells(i+1,j+1).Font.Bold =1;
    }
   }
  }
  oXL.Visible = true;
  ōXL = null;
  }catch(e){}
  finally{
        idTmr  =  window.setInterval("Cleanup();",1);
  }
}

 

function exportWordInfo(titleName,calcIndex)
{
  try{
      var PrintA = document.all("tableRpt");
      var row_count = PrintA.rows.length-1;
      var col_count = PrintA.rows(0).cells.length;

      var WordApp=new ActiveXObject("Word.Application");

      var wdCharacter=1;
      var wdOrientLandscape = 1;
      var myDoc=WordApp.Documents.Add();

      WordApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
      WordApp.Selection.Font.Size=12;
      WordApp.Selection.Font.Bold=1;
      WordApp.Selection.TypeText(titleName);
      WordApp.Selection.Paragraphs(1).Alignment=1;
      WordApp.Selection.MoveRight(1);
      WordApp.Selection.TypeParagraph();
      WordApp.Selection.TypeParagraph();
      WordApp.Selection.Font.Bold=0;
      var info=document.all("info").innerHTML
      WordApp.Selection.Font.Size=10;
      WordApp.Selection.TypeText(info.replace(/&nbsp;/g,'  '));
      WordApp.Selection.Paragraphs(1).Alignment=3;
      WordApp.Selection.MoveRight(1);
      WordApp.Selection.TypeParagraph();
      WordApp.Selection.TypeParagraph();
     var myTable=myDoc.Tables.Add (WordApp.Selection.Range, row_count,col_count)
     var TableRange;

     for (i =0;i<row_count;i++)
     {
       for (n =0;n<col_count ;n++)
       {
          with (myTable.Cell(i+1,n+1).Range)
          {
            font.Size = 10;
            if(i==0)
            {
               font.Bold =1;
            }
            if(n>=calcIndex)
              ParagraphFormat.Alignment=2;
            else
              ParagraphFormat.Alignment=0;
            if(i==0)
              ParagraphFormat.Alignment=1;

            InsertAfter(PrintA.rows(i).cells(n).innerText);
          }
        }
      }

      row_count = 0;
      col_count = 0
      WordApp.Application.Visible=true;
  }catch(e){}
      finally{
         idTmr  =  window.setInterval("Cleanup();",1);
      }
}


function choseProject(customerID)
{

 window.open("../project/choseproject.jsp?customerID="+customerID , "cre", "height=400,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no");

}


//edit supplier edit by qing 1029
function show_editVendor(ID){
  reValue=window.open("../supplier/editcilent.jsp?id="+ID, "editvendor", "height=600,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
}

//edit supplier edit by qing 0127
function show_editCustomer(ID){
 reValue=window.open("../cilent/editcilent.jsp?id="+ID, "editclient", "height=600,top=0,left=0, width=800, toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
}

function checkPeriod(period)
{
     var url = '../voucher/autocode';
     var pars = "type=checkPeriod"+"&period="+period+"&t="+Math.random();
     var bankAjax = new Ajax.Request(url,{method: 'post', parameters: pars, onComplete: showMsg});
}

function checkPeriod1(period)
{
     var url = '../voucher/autocode';
     var pars = "type=checkPeriod"+"&period="+period+"&t="+Math.random();
     var bankAjax = new Ajax.Request(url,{method: 'post', parameters: pars, onComplete: showMsg1});
}


function showMsg(requestObj)
{
  var resultf=requestObj.responseXML.getElementsByTagName("code");
  var resultc=requestObj.responseXML.getElementsByTagName("check");
  periodExist=resultf[0].firstChild.nodeValue;
  checkOut=resultc[0].firstChild.nodeValue;
  if(periodExist=="0")
  {
      alert(document.all("periodNotFound").value);
      return ;
  }

  if(checkOut==1)
  {
      alert(document.all("periodCheckOut").value);
      return ;
  }
  document.all("form").submit();
}


function showMsg1(requestObj)
{
  var resultf=requestObj.responseXML.getElementsByTagName("code");
  var resultc=requestObj.responseXML.getElementsByTagName("check");
  periodExist=resultf[0].firstChild.nodeValue;
  checkOut=resultc[0].firstChild.nodeValue;
  if(periodExist=="0")
  {
      alert(document.all("periodNotFound").value);
      return ;
  }

  if(checkOut==1)
  {
      alert(document.all("periodCheckOut").value);
      return ;
  }
var   tb   =   document.getElementsByTagName("table");
tb[1].rows[0].cells[1].disabled=true;
  document.all("form").submit();
}

 

 


 

 


TAG: JAVA java

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-10-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 9209
  • 日志数: 19
  • 图片数: 1
  • 建立时间: 2007-04-22
  • 更新时间: 2007-09-03

RSS订阅

Open Toolbar