Apache
  Home arrow Apache arrow Page 2 - Programmatically Manipulating Microsoft Ex...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Programmatically Manipulating Microsoft Excel Spreadsheets with the Apache POI API
By: Kulvir S. Bhogal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 51
    2003-11-26

    Table of Contents:
  • Programmatically Manipulating Microsoft Excel Spreadsheets with the Apache POI API
  • Let’s Learn How to Write to a Spreadsheet
  • Let’s Learn How to Read From a Spreadsheet
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Programmatically Manipulating Microsoft Excel Spreadsheets with the Apache POI API - Let’s Learn How to Write to a Spreadsheet


    (Page 2 of 4 )

    The spreadsheet we’ll be manipulating is rather simple. A screen shot of the spreadsheet, named sales.xls and the graph embedded in the spreadsheet is shown below.


    Figure 1: Our untouched spreadsheet, sales.txt.

    The sales.xls file consists of a simple spreadsheet which represents sales amounts for an imaginary company in the states of Texas, California, and New York. To see what we can do with the POI API, we’ll alter the values of our sales values programmatically. The code in Listing 1 does just that. We change the values for the cell values of B2, the sales of the state of California.

    As you can see, the process is quite simple. First, we open our Excel file. From there, we pinpoint the appropriate cell we want to manipulate. Notice how the Apache POI provides values objects such as HSSFRow and HSSFCell which programmatically correspond to rows and cells from the Excel world. Note how rows of the spreadsheet are zero indexed while column indexing starts with 1.

    Before writing to a cell, we specify our cell type: CELL_TYPE_NUMERIC. Our desired changes are reflected when we use the write method of our HSSFWorkbook object. By executing the code in Listing 1, we change the value of cell B2 to 89000. The resulting altered spreadsheet and embedded graph are shown in Figure 2.


    Figure 2: Our Programmatically Altered Spreadsheet, sales.xls.

    More Apache Articles
    More By Kulvir S. Bhogal


     

    APACHE ARTICLES

    - Programmatically Manipulating Microsoft Exce...
    - Installing PHP under Windows
    - Compressing Web Content with mod_gzip and mo...
    - Compressing Web Output Using mod_deflate and...
    - Setting Up Apache 2.0.45 to Parse PHP Pages
    - Custom Error 404 Documents with PHP
    - Using Apache and PHP on Mac OS X
    - ASP: Active Sessions, Active Logins and Tota...
    - Working With Oracle on Windows: Part 1
    - The Quick-n-Dirty Guide to Setting Up Apache...
    - Installing Apache With SSL: The Complete Gui...
    - 7 Powerful .htaccess Customization Tips
    - Trap And Get Notified: A Practical Solution ...
    - One Way To Use Server Side Includes
    - Using ForceType For Nicer Page URLs







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway