Skip to Content
Introduction

I see numerous questions on forum about how to read and write an excel file from Java. So, I have decided
to present java code to create an excel file and display it in EP6 portal using AbstractPortalComponent.
I am going to use HSSF’s apis to create an excel file. HSSF is part of open source POI project.
These apis can also be used to read microsoft excel file from java. For more information about POI check out the site http://jakarta.apache.org

Required Jars:

You can download the following jars from http://jakarta.apache.org.
servlet.jar, poi-2.5.1-final-20040804.jar, poi-contrib-2.5.1-final-20040804.jar, poi-scratchpad-2.5.1-final-20040804.jar

Steps to create PAR component

Step 1:

Create an AbstractPortalComponent using Eclipse or Netweaver Studio. Add the above jars to PORTAL-INF->lib folder.

Step 2:

Add the following lines to doContent method.

Step 3:

Deploy it in portal and run it. You should get the following output.
image
To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Prakash,

    this is a nice example. Allow me some additions to it:

    First, Jakarta have some good beginner tutorials on their own pages (http://jakarta.apache.org/poi/hssf/quick-guide.html).

    Second, for “not-so-sophisticated” purposes, one can alternatively use the “HTML Excel” trick. Simply write an HTML table with the very same MIME type as you did in your output (without head and body tags, just a simple table).

    Lastly, I suggest adding a “Content-Disposition” header to the output stream. This allows to assign a file name if the user wants to download the file locally (instead of opening it directly in a browser).

    Regards, Dominik

    (0) 
  2. Hemant Sharma
    Hi All,

    Thanks for a nice blog.
    I have succesfully followed your blog for Abstract Portal Compoent this is working fine , but when i do the same for JSP dynpage it shows some junk character’s and does not open excel
    Probably i guess some changes in below section:
    HttpServletResponse  res = request.getServletResponse(true);
              try {
                   res.setContentType(“application/vnd.ms-excel”);
                   wb.write(res.getOutputStream());
              } catch (Exception e) {
                   e.printStackTrace();
              }

    Any help in case of JspDynpage will be apprciated.

    Regards
    Hemant

    (0) 

Leave a Reply