Saturday, July 14, 2012

Export to excel in salesforce using HTML Table & jQuery


In the last post I mentioned export to excel in salesforce using another plugin called downlaodify. Many people did not like it using a flash plugin for export. So decided to research export in another way.
In my research I found excel and open office recognizes HTML Table and displays in excel format. My colleague Murali has an interesting idea the we can send variable in salesforce from one page to another page. By using the same controller for two pages we easily access variable in another page.Export can be acheived using two visualforce pages and same controllerfor both of them, by sending a hidden variable from one page to another page in the html table format.
Apex Page refference methods from apex can used to redirect from one page to another page.
Consider the governer limits while using this code. This do not work when you cross beyond the view state.
I tested for 1000- 5000 records with 12- 15 columns it works fine for me(without text area).

You can see live demo  @  http://ugeshcrm-developer-edition.ap1.force.com/ExportToExcelDisplay

Apex Class:
public with sharing class ExportToExcel{
 
     public String exportDataString {get; set;}  

     public ExportToExcel() {}

   //Apex Page refference methods from apex can used to redirect from one page to another page.
     public ApexPages.PageReference goToExportPage() {
        return Page.ExportToExcel;
     }  
}

Visualforce page: Display
<apex:page controller="ExportToExcel" sidebar="false" title="Export">
     <!-- Static Resource Includes: Jquery and css files  -->
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.JQuery,'js/jquery-1.5.2.min.js'))}"/>
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.JQuery,'js/jquery-ui-1.8.13.custom.min.js'))}"/>
    <apex:stylesheet value="{!JSENCODE(URLFOR($Resource.JQuery, 'css/redmond/jquery-ui-1.8.11.custom.css'))}"/>

    <style>
        #newspaper-b {
            font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
            font-size: 12px;
            margin: 45px;
            width: 480px;
            text-align: left;
            border-collapse: collapse;
            border: 1px solid #69c;
        }
        #newspaper-b th  {
            padding: 15px 10px 10px 10px;
            font-weight: normal;
            font-size: 14px;
            color: #039;
        }
        #newspaper-b tbody {
            background: #e8edff;
        }
        #newspaper-b td {
            padding: 10px;
            color: #669;
            border-top: 1px dashed #fff;
        }
        #newspaper-b tbody tr:hover td {
            color: #339;
            background: #d0dafd;
        }

    </style>
     <apex:sectionHeader title="Export Table" />

     <script type='text/javascript' language='javascript'>
        var j$ = jQuery.noConflict();
        function exportTableData(){
            j$(".exampleDataToExport").val(j$("#containerTable").html());
            goToExportPage();
        }
     </script>
    <apex:form >
        <a style="text-decoration: underline;cursor: pointer;margin-left:480px;font-weight:bold;font-size: 15px;" class="dummyCustomExport"  onclick="exportTableData()" title="export"><b>Export</b></a>

        <div id="containerTable">
            <table id="newspaper-b" class="dummyExportTableClass" summary="2007 Major IT Companies' Profit">
                <thead>
                    <tr>
                      <th scope="col">Company</th>
                      <th scope="col">Q1</th>
                      <th scope="col">Q2</th>
                      <th scope="col">Q3</th>
                      <th scope="col">Q4</th>
                    </tr>
                </thead>
                <tbody>
                  <tr>
                      <td>Microsoft</td>
                      <td>20.3</td>
                      <td>30.5</td>
                      <td>23.5</td>
                      <td>40.3</td>
                  </tr>
                  <tr>
                      <td>Google</td>
                      <td>50.2</td>
                      <td>40.63</td>
                      <td>45.23</td>
                      <td>39.3</td>
                  </tr>
                  <tr>
                      <td>Apple</td>
                      <td>25.4</td>
                      <td>30.2</td>
                      <td>33.3</td>
                      <td>36.7</td>
                  </tr>
                  <tr>
                      <td>IBM</td>
                      <td>20.4</td>
                      <td>15.6</td>
                      <td>22.3</td>
                      <td>29.3</td>
                  </tr>

                </tbody>
            </table>
        </div>
        //action function redirects to another page.
        <apex:actionFunction name="goToExportPage" action="{!goToExportPage}"/>
        <apex:inputTextarea id="ExportDataString" value="{!exportDataString}" styleClass="exampleDataToExport" style="display:none"/>
    </apex:form>
</apex:page>

Visualforce page: Export page
<apex:page controller="ExportToExcel" contentType="application/vnd.ms-excel#export.xls"  title="Export To Excel" cache="true">
  {!(exportDataString)}
</apex:page>

Please feel free to comment if you have any better ideas andto imporove code and any other export methods.

Monday, January 30, 2012

Export to excel in Salesforce from client side

From the last few weeks I was trying export in the salesforce from the visualforce page.
Salesforce has export functionality in the dashboards and reports.I does not have
export functionality by default for the pages.For every page for the export we have to write a new
page for the export.As we are using JqGrid in the salesforce pages for each grid we have to write
export functionality in a different page and this is pain.

Recently i heard the client side export using flash.
I did a little research and found a downloadify client side flash plugin to do export and this may help you.

Downloadify -  https://github.com/dcneiner/Downloadify
Jquery - http://jquery.com/

Upload Downloadify and JQuery as static resources in salesforce.
If you want JQuery UI you can also upload to static resources.

You can find demo at https://ugeshcrm-developer-edition.ap1.force.com/

Need to install flash player to for export.

Visualforce Page:

<apex:page sidebar="false" title="Export">
     <!-- Static Resource Includes: Jquery,Jqgrid libraries -->
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.JQuery,'js/jquery-1.5.2.min.js'))}"/>
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.JQuery,'js/jquery-ui-1.8.13.custom.min.js'))}"/>
    <apex:stylesheet value="{!JSENCODE(URLFOR($Resource.JQuery, 'css/redmond/jquery-ui-1.8.11.custom.css'))}"/>
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.Downloadify,'js/swfobject.js'))}"/>
    <apex:includeScript value="{!JSENCODE(URLFOR($Resource.Downloadify,'js/downloadify.min.js'))}"/>

    <!--Style to display portlets -->
    <style>
        #newspaper-b  {
            font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
            font-size: 12px;
            margin: 45px;
            width: 480px;
            text-align: left;
            border-collapse: collapse;
            border: 1px solid #69c;
        }
        #newspaper-b th  {
            padding: 15px 10px 10px 10px;
            font-weight: normal;
            font-size: 14px;
            color: #039;
        }
        #newspaper-b tbody   {
            background: #e8edff;
        }
        #newspaper-b td   {
            padding: 10px;
            color: #669;
            border-top: 1px dashed #fff;
        }
        #newspaper-b tbody tr:hover td   {
            color: #339;
            background: #d0dafd;
        }
    </style>
     <apex:sectionHeader title="Export table" />
    <div id="containerTable">
        <table id="newspaper-b" summary="2007 Major IT Companies' Profit">
            <thead>
                <tr>
                    <th scope="col">Company</th>
                    <th scope="col">Q1</th>
                    <th scope="col">Q2</th>
                    <th scope="col">Q3</th>
                    <th scope="col">Q4</th>
                </tr>
            </thead>
                <tfoot>
                <tr>
                    <td colspan="5"><em>The above data were fictional and made up, please do not sue me</em></td>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>Microsoft</td>
                    <td>20.3</td>
                    <td>30.5</td>
                    <td>23.5</td>
                    <td>40.3</td>
                </tr>
                <tr>
                    <td>Google</td>
                    <td>50.2</td>
                    <td>40.63</td>
                    <td>45.23</td>
                    <td>39.3</td>
                </tr>
                <tr>
                    <td>Apple</td>
                    <td>25.4</td>
                    <td>30.2</td>
                    <td>33.3</td>
                    <td>36.7</td>
                </tr>
                <tr>
                    <td>IBM</td>
                    <td>20.4</td>
                    <td>15.6</td>
                    <td>22.3</td>
                    <td>29.3</td>
                </tr>
            </tbody>
        </table>
    </div>

    <script type='text/javascript' language='javascript'>
      var j$ = jQuery.noConflict();
      j$(document).ready( function () {
        var exportdata = j$('#containerTable').html();
        Downloadify.create('downloadify',{
              filename: function(){
                  return j$('#filename').val();
              },
              data: function(){
                  return exportdata;
              },
              swf: "{!URLFOR($Resource.downloadify,'media/downloadify.swf')}",
              downloadImage:"{!URLFOR($Resource.downloadify,'images/download.png')}",
              width: 100,
              height: 30,
              transparent: true,
              append: false
          });
      });
    </script>

    <form>
        <p style ="display:none">
            <label for="filename" >Filename</label><br />
            <input type="text" name="filename" value="exportfile.xls" id="filename" />
        </p>
        <p id="downloadify" style="margin-left:100px;">
            You must have Flash 10 installed to download this file.
        </p>
    </form>
</apex:page>
     

Feel free to comment and share your ideas in improving the post.

Wednesday, February 9, 2011

How to integrate phpdocumentor in eclipsePDT

You can download the phpdocumentor from the below url

http://sourceforge.net/projects/phpdocu/files/PhpDoc/phpDocumentor-1.4.3/PhpDocumentor-1.4.3.zip/download

keep the phpdocumentor project in the WWW folder

If we want to integrate the phpdocumentor within eclipse.

1. Open the 'External Tools Configurations ' Dialog through 'Run -> External Tools -> External Tools Configurations' then you find the dialogbox as shown below.

2. Rightclick on the program and then click new.(click on the + mark as shown in fig above "type filter text")



3. Enter the following data:

Name : phpdocumentor

Location : C:\wamp\bin\php\php5.2.9-2\php-win.exe (give the php path executables into loaction)

Working Directory : C:\wamp\www\PhpDocumentor(as we already downloaded the PhpDocumentor into www )
4. In the arguments field type

"  phpdoc -d "C:\wamp\www\extoledev" -t "C:\wamp\www\testphpproj\doc" -o HTML:Smarty:default "

my php project is located at C:\wamp\www\extoledev and its document should be created to testphpproj(C:\wamp\www\testphpproj\doc)

-d is directory(main php application or project directory to which you have to create documentation for it )

-t is target(target directory to which you have save the documentation.)

-o is output(output file as pdf or html etc.)

keep -O HTML:Smarty:default for html output.
 
Leave me a comment if you need any assistance..

Friday, October 22, 2010

How to implement editable grids in drupal

For the past few months i was trying to implement editable grids in drupal.But at last I found an way to implement to implement editable grids in drupal.Lot of discussions happened in the drupal forum
http://drupal.org/node/801078  and finally got any editable grid from that discussions in drupal at http://drupal.org/node/801078#comment-3272150 .
Demo is avilable at  http://testsandbox.iblogger.org/jqgrid_example/showgrid.
Thanks to  Rajan M one who created grid.

Tuesday, February 9, 2010

how the Injection flaws overcome in drupal

Previously i was in the domain of ASP.net .Now i have moved to PHP-CMS based technologies in the open source environment.Now the CMS i was using was Drupal.
 As i had some experience with ASP.net and MSSQL, i know how it overcomes injection problem as we pass parameters into it to solve the injection problem in ADO.net. I also have a doubt how my Drupal CMS handles SQL injection in its DBs
If  we login as in the above process the query will be in the form of

SELECT uid FROM users WHERE  name=“Admin”  OR uid=1 OR “1”=“1” AND  password=“xxxxxxxxx” 

The sql query runs in the above format if we login through the admin previlages.

But drupal actuallly provides built in sql injection attack prevention

db_query family of functions will take care of escaping user input for you as long as you pass them as parameters to the function and don't include them as part of your SQL statement.It is not possible to inject arbitrary SQL.
Drupal provides  functions to process URLs and SQL arguments, making security for users.Drupal7 have more complex code to overcome regard insecure database..

Thursday, October 29, 2009

how to install lamp and phpmyadmin 3.2.2.1 in centOS 5.3

After reffering some sites and blogs at last i got LAMP and phpmyadmin-3.2.2.1 installed correctly in my centos 5.3
If you want to install LAMP, first you need to install php and mysql .
To do this use the following commands in your terminal

#yum install php
#yum install php-gd
#yum install php-mbstring
#yum install mysql
#yum install mysql-server
#yum install php-mysql

The default version of php on  centOS5.3  is php-5.1, if you have to work with the phpmyadmin you need to upgrade it for 5.2 or higher version

Below command shows the existing php version
#php -v

To upgrade or install  5.3 version first install 5.1 by the above methods to get rid of php-mbcrypt problems and some errors. And i suggest you to install php 5.1 first and then follow the below steps.I found some repos on some sites it would fairly work for you also...

To install, first you must tell rpm to accept rpm’s sign

#rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy

Then add the yum repository information

#cd /etc/yum.repos.d/
#wget http://repo.webtatic.com/yum/webtatic.repo
 
 Install php
 
#yum --enablerepo=webtatic install php
 
And then install webserver apache
 
#yum install httpd
 
Now, start the Apache/httpd server
 
# /etc/init.d/httpd start
# chkconfig httpd on    (to run apache automatically when system runs)
 
After that test it in browser by typing http://localhost/
 
If we get apache welcome page webserver is installed correctly.
 
Now to  test php go to file system var/www/html
 

 
Create a file and name it as info.php and give permission to acess it i,e access i,e chmod 777 info.php (for testing)
Type the following lines in info.php
 

phpinfo();
?>
 
and save the file
 
Open your webbrowser and you can acess it by by typing http://localhost/info.php and you can find the version number in a blue screen and mysql details
 
And coming to mysql  first
 
#mysql
 
we get the following error as ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
 
To fix:

First start the mysql daemon, then type mysql

#/etc/init.d/mysqld start

#mysql
it comes in terminal as
>mysql

by default mysql has no password and To update mysql root password

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;

then to exit
mysql>exit;

To test it
#mysql -u root -p
#Enter password : new-password
it takes to mysql and exit from there

To install phpmyadmin

#cd /var/www/html

If not avial able the below link as phpmyadmin go to link http://sourceforge.net/projects/phpmyadmin/files/ and browse the version you want and download.

#wget http://nchc.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.2.2.1-english.tar.gz
#tar zxvf phpMyAdmin-3.2.4-english.tar.gz
#mv phpMyAdmin-3.2.4-english phpmyadmin
#cd phpmyadmin
#cp config.sample.inc.php config.inc.php

Edit config.inc.php file


#nano config.inc.php    and go to line and modify if you wish you can keep blowfish secret also

$cfg['Servers'][$i]['auth_type'] = ‘http‘; # default is cookies

Restart your apache webserver for updating the setting

# /etc/init.d/httpd restart
# /etc/init.d/mysqld restart

To keep always apache on when system is rebooted

#chkconfig httpd on
#chkconfig mysqld on

You can test  phpmyadmin by http://localhost/phpmyadmin

Give the user name as root and passord  (new-password) in popup

Hope that all works fine..

Wednesday, September 16, 2009

Website design ideas

1.Go through as many as example sites and do the layout work
2.Build the webite on the lowest screen resolution and build your wesite on this resolution.
3.Use Dhtml menus ,graphics and flash in eye caching manner.
4.Use tables creatively in html and measure them in percentages.
5.Insert images and content and test your site in different resolutions.