Tuesday, June 4, 2013

Re: Export CellTable data to PDF and Excel Format using UIBinder

hey i have to GWT in my project, have u ever used TableToExcelClient widget? I followed the same instructions as per the https://code.google.com/p/gwt-table-to-excel/wiki/Usage 

but i am not able to download the data

here is my code

final CellTable<Contact> table = new CellTable<Contact>();
table.setPageSize(3);
 
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
     @Override
     public String getValue(Contact object) {
       return object.name;
     }
   };
   table.addColumn(nameColumn, "Name");
   
   DateCell dateCell = new DateCell();
   Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
     @Override
     public Date getValue(Contact object) {
       return object.birthday;
     }
   };
   table.addColumn(dateColumn, "Birthday");

   TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
       @Override
       public String getValue(Contact object) {
         return object.address;
       }
     };
     table.addColumn(addressColumn, "Address");


final TableToExcelClient tableToExcelClient = new TableToExcelClient(table);
hPanel.add(tableToExcelClient.getExportWidget());

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee">

  <!-- Servlets -->
  <servlet>
      <servlet-name>sampleServlet </servlet-name>
      <servlet-class>com.fedex.forecast.datamart.server.SampleServiceImpl</servlet-class>
      
  </servlet>
  
  <servlet>
          <servlet-name>gwtTableToExcelServlet</servlet-name>
          <servlet-class>com.googlecode.gwtTableToExcel.server.TableToExcelServlet</servlet-class>
        </servlet>
  
  <servlet-mapping>
      <servlet-name>sampleServlet </servlet-name>
      <url-pattern>/sample2/sampleservice </url-pattern>
  </servlet-mapping>
  
  <servlet-mapping>
                <servlet-name>gwtTableToExcelServlet</servlet-name>
                <url-pattern>/sample2/excel</url-pattern>
        </servlet-mapping>
 
  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>Sample2.html</welcome-file>
  </welcome-file-list>

</web-app>

gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  When updating your version of GWT, you should also update this DTD reference,
  so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module rename-to='sample2'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

  <!-- Other module inherits                                      -->
  
  <inherits name="com.googlecode.gwtTableToExcel.gwtTableToExcel" />

  <!-- Specify the app entry point class.                         -->
  <entry-point class='com.fedex.forecast.datamart.client.Sample2'/>
 
  <!-- Tomcat will listen for this from the server and waits for rpc request in
this context -->
  
<!--   <servlet class="com.fedex.forecast.datamart.server.PoolManager" path="/PoolManager" /> -->

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>
 
  

</module>

but when i run the application i am not able to download excel and moreover i get an error (below message) - I have defined my url path in the web.xml as /sample/sampleservice/excel - I dont  know why it still takes it as sample/excel. When i changed it in the browser to /sample/sampleservice/excel and run it i get javanullpointerexception. Can you please let me know what could be the issue

HTTP ERROR: 404

NOT_FOUND

RequestURI=/sample2/excel

Powered by Jetty://




On Tuesday, June 4, 2013 11:07:47 AM UTC-5, Alain wrote:
If you want to do it clientside  I could recomment using ClientIO


See it in action here 





2013/6/4 Shashank Beerla <shashan...@gmail.com>
hey can u send me a complete code for celltable export to excel


On Friday, May 25, 2012 9:21:38 AM UTC-5, Joseph Lust wrote:
The gist is to:
  1. Get a list of all records you need to export from the celltable on the client browser (and the sorting information).
  2. Return this to the server.
  3. Fetch all the information from (1).
  4. Build into an Excel or CSV output using POI or similar.
In reality it can be quite a pain. I implemented it in ExtJs grids using POI and had to have columns in any order user had rearranged them to, columns shown/hidden if user had changed them, numeric values as numeric type in exported Excel file... etc. You probably want to try to use a library to achieve this rather than write it yourself.

I've not used this library, but it looks like a good start: GWT-Table-To-Excel http://code.google.com/p/gwt-table-to-excel/
Note that the library uses HTML output, which is a hack (that even ASP.Net recommends... LOL). You'll get a warning if you open a HTML table in Excel that it is not the proper format, but then Excel will load it anyway. If you need rich, native Excel exports, you'll probably need to write your own POI framework.



Sincerely,
Joseph

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.

To post to this group, send email to google-we...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment