Excel Note
 
 
 
Excel Port
The Excel port functionality has been incorporated in zeroCode to enable the export of data from an HTML page to an excel sheet. This type of mechanism is for the first time implemented in zeroCode.
 New Features

This code can be implemented only in the list pages. The code invokes the excel application and sends the data into the excel sheet. You can save the page if required. 

On body load a function called sendtoexcel() is called. The function checks for a particular flag or condition and if the condition or flag is satisfied then the excel is invoked, else it exits out of the function. Initially the condition or the flag is false.
A button (XLport) is provided to you on all the templates. Click on this button a function showexcel () is called, where the flag or condition is made true. The first page is then loaded where the on load function i.e. sendtoexcel () is called. Since the condition is true now, it will in turn invoke the excel application and send the data to excel. The data will be in the form of table items. Number of records per page is not the same always. It could be (Nolimit, 1, 5, 10, 15, 20, 25, 30) any number. No matter from whichever page you click the button, the data is transferred from the first page.  In this way all the pages’ data is transferred page wise to the excel sheet. This may result in flickering on the screen. Once the data from one page is transferred to excel, the sheet gets saved then when the next page data has to be transferred it will invoke the same saved file and put in the data, for which we have used getObject() method in our function. The saved file will be assigned the name, which will have date and time with “A” as the starting letter.
After the data transfer the page is redirected to the first page, only if the number of pages is more than 1.
After the data transfer the page is redirected to the first page, only if the number of pages is more than 1.
Conditions:
In the internet properties, security/custom level option for the ActiveX objects should be enabled.
General Changes
Login to the Zerocode development environment. As you login you can see the banner on top, a menu frame on the left hand side and the list of site/s created by you on the right side (that is the main page). When you click on the site on in which you wish to make changes, a tree structure is displayed in the left of the main frame, which contains folders with collection of htmls and javascript files. The scope is to provide excel port utility in the created site, your need to focus on  list and browseby templates and the meta template, which create them.
Changes to be made in metaTemplate for auto generated list templates

You need to make changes to the meta templates, if the changes need to show up in all the auto generated Templates. The path will be <sitename>MetaTemplates. In this directory changes have to be done to the content of listTemplate.html. Given below are the steps to be followed to implement excel port in the template.

Body on load syntax should be as shown below:
<body class=PageBody onLoad=‘javascript:sendtoexcel ()'>
The button which calls the excel application should be placed in the form as shown below:
<input type='button' value='XLPort' onclick=‘javascript: showexcel ()'>
Include the function showexcel () and sendtoexcel () in the listTemplate.html with in the form tag.
Regenerate the site to get the new changes into the auto list template.
Changes to be made in Template
The following steps need to be followed in order to implement excel port in the template.

Body on load syntax should be as shown below.
<body class=PageBody onLoad=‘javascript:sendtoexcel ()'>
The button which calls the excel application should be placed in the form as shown below
<input type='button' value='XLPort' onclick=‘javascript: showexcel ()'>
Include the function showexcel () and sendtoexcel () in the template with in the form tag.
Excel Port By Creating a UDM
There is another way to implement the above mechanism, that is by creating a UDM. The functionality is same as the above.
Excel Invoking functionality
 
 
Create copies of a list UDM and its HTML in the custom directory.
Set the paging option on the UDM to No limit.
This button has to be inserted in the calling html or page.

a.  <input type='button' value='XLPort' onclick=‘javascript: showexcel ()'>

From the first UDM call the created UDM by putting in the function showexcel (). Replace the html name in the function with the calling html name
Body on load syntax should be as shown below.

<body class=PageBody onLoad=‘javascript:sendtoexcel ()'>

Insert; excel invoking function that is the sendtoexcel () in the created   HTML, to take data directly to XL, as if there were only one page. This function is called when the html is loaded (body onload). Make changes to field names and html names.

The function involves syntax of both javascript and freemarker.

 
Some possible free marker code used in Pagination
Older browsers (Netscape 1.X, Internet Explorer 2.X) do not support JavaScript and therefore do not recognize the <script> tag. These older browsers will ignore the <script> tag completely and simply display the JavaScript code in the browser, as if it were regular text on a page. To avoid this, surround your JavaScript code with comment tags, as shown below:

<script language="JavaScript">

<!--
...code...
// -->

</script>

This way, if the browser doesn't recognize the <script> tag, it will ignore everything between the <!--(begin comment) and the --> (end comment) tags. Browsers that do recognize the <script> tag are aware of this limitation in older browsers and will ignore the <!-- and the --> tags, but will still interpret the JavaScript code. Note that the // in front of the --> is very important. Do not leave this out!

Notice that FreeMarker is invoked twice in zeroCode – once when the site is generated (to build the templates) and once when the page is generated. To ensure that the first run of FreeMarker at gen-time ignores the curly-brackets that need to be available at run-time, the special tag is declared and used as a replacement for the {character. So also for the character} – the tag is used.

For more information about FreeMarker tags, please click here.