JavaScript in built sites

 
 
  
     
function sendtoexcel(stoexcel)


 var blnflag; // The Boolean flag 
 var z; // variable to store file name from the URL
 // Following are the variables to capture the URL values.
          var flg1;
          var flg2;
          var flg3;
          var flg4;

 /* The code shown below validates the url and captures the value for two flags i.e 
1) whether the button is clicked and 
2) the saved file name */

  var docurl=document.location.href;
  var docarr=docurl.split("=");
  if(docarr.length>5)

 {
   flg1=docurl.split("=");
   flg3=docarr[5].split("=");
   flg4=docarr[6].split("=");
   flg2=flg3[0].substr(0,1);
   z=flg4;

  }
// According to the date and time the file name is created
// For e.g. A15102000101844.XLS

 if(z==null){ //z is the file name which is passed as a query string. It checks whether z is null.
        var d=new Date();
        var month=d.getMonth();
        var year=d.getYear();
        var h=d.getHours();
        var m=d.getMinutes();
        var s=d.getSeconds();
        var d=d.getDate(); 
        flname="A"+d+month+year+h+m+s+". XLS"; // The file name gets the value here.
   }
else
  {
   flname=z; // The filename from z is carried to flname.
                 } 
//The code below captures the value of click page and the number of records per page

      var exApp;
      var ActiveSheet ;
      var blnflag
      if(flg2=="T")

{

// Below is the syntax for the clicked page.
     var pgnum="";
if(pgnum=="")

{
   pgnum=1;
                                       }

// Below is the syntax for the number of records per page.

   var s="";
if (s=="")

{
    s=1;


// If the page number is 1 then the syntax below gets executed and a flag is made false. 

if (pgnum == 1)
     {
       var exApp = new ActiveXObject("Excel.Application") 
       exApp.Visible=true; 
       exApp.Workbooks.Add;
       exApp.Worksheets.Add;
       ActiveSheet = exApp.Workbooks(1).Worksheets(1);
       blnflag="False"; 
     }
else
// If the page number is >1 then the syntax below gets executed and a flag is made true.

     {

       var exApp = GetObject(flname,"Excel.Sheet");
       blnflag="True"; 
     }
       var i=2;
       var j=2; 

// The following syntax is to display the headings of the tables as in the htmll pages.

    exApp.ActiveSheet.Range("A2","Z2").Font.Bold=true; 
    exApp.ActiveSheet.Cells(i,j).Value=" #";
    j=j+2;


        exApp.ActiveSheet.Cells(i,j).Value="Address Type";
    j=j+2;


    exApp.ActiveSheet.Cells(i,j).Value="Address Address Typecount";
    j=j+2;


    i=i+2;
// The following syntax ensures that the previous data in the XL is not overwritten. 

if(pgnum==1)

  {
     var i=4;
  }
else
  {
    var i=(s*pgnum)-(s-4);
  }
// Following is the listing of data to the XL from the table and the increment of the cells is done accordingly.
  <list Address_Type.Address_Type as e1>
  <assign id e1.Id>

   var j=2; 

    <assign cellContent e1.Id>
   exApp.ActiveSheet.Cells(i,j).Value = ""; 
   j=j+2; 


  <assign cellContent e1.Address_Type>
  exApp.ActiveSheet.Cells(i,j).Value = ""; 
  j=j+2; 


  <assign cellContent e1.Address__Address_Type>
  exApp.ActiveSheet.Cells(i,j).Value = ""; 
  j=j+2; 

  i=i+1;
  </list>
//The file is saved accordingly

if(blnflag=="False")
    {
     exApp.ActiveSheet.SaveAS(flname);
     var pgn=""; 
     if(pgn=="")

 {
     pgn=1;
 } 
if(parseInt(pgnum) != parseInt(pgn))
 {
  exApp.Workbooks.Close;
 }


 }
else
    if(blnflag=="True") 
  {
    App.windows(1).Visible = "True";
    exApp.Save ;
   } 

// The control is passed to the next page. It checks if the clicked page and the total number of pages are equal. //Till it is equal it transfers the data.

   var pgn=""; 
   if(pgn=="")

  {
   pgn=1;
  } 
     if(pgnum==""){
     pgnum=1;
  } 
     if(parseInt(pgnum) < parseInt(pgn))
  {
     var                      str="/zcSite/faqx/auto/list/Address_Type/pagingAction?search__id=&paging__node=1&page__number="+(parseInt(pgnum)+parseInt(1))+"&order__by__1=&stoexcel=T&flname="+flname;
     window.location.href=str; 
  }
//After the transfer of data the first page is displayed 

    if(parseInt(pgnum) == parseInt(pgn))
  {

        var str="/zcSite/faqx/auto/list/Address_Type/pagingAction?search__id=&paging__node=1&page__number=1&order__by__1=";
    window.location.href=str; 
   }


   }
   }
</script>