Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Creating excel spreadsheet using Apache POI

795672Aug 18 2010 — edited Aug 18 2010
Hi, I know this isnt a POI forum but I have looked through the forum and some people seem to have knowledge of the API so I thought I might get some help here. I am creating a workbook with multiple sheets and it seems to be working ok, the problem that I have is that I cannot add a second cell to each sheet unless I add a third.

At the moment the this third cell is actually just an empty string as the data I am working with only has 2 columns. My code works fine with this hack, but ideally I would like to find out what I am doing wrong for this to be needed. If anyone can help I would be grateful. I have added the method I have written.

The object 'data' is a hashtable, and I know whilst not ideal I am using a standard inhouse utility method that calls stored procedures and it returns its output as nested hashtables...

Thanks.
public void getWorkSheet(HSSFWorkbook workbook) {
            HSSFSheet patientSheet = workbook.createSheet(PATIENT_SHEET);

            for (int i = 1; i <= data.size(); i++) {               
                Hashtable rec = (Hashtable) data.get(i);
                String orgCode = (String) rec.get(ORG_CODE);
                String patientCount = (String) rec.get(PATIENTS_ADDED);

                HSSFRow row = patientSheet.createRow((short)i - 1);
                HSSFCell cellOne = row.createCell(0);
                cellOne.setCellValue(new HSSFRichTextString(orgCode));

                HSSFCell cellTwo = row.createCell(1);
                cellTwo.setCellValue(new HSSFRichTextString(patientCount));
                //This line below is the hack, I dont need a 3rd cell but without it
                //the second cell will not render in the spreadsheet
                HSSFCell cellThree = row.createCell(2);
                cellThree.setCellValue(new HSSFRichTextString(""));
            }
        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2010
Added on Aug 18 2010
9 comments
1,071 views