Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:09:26+00:00 2026-05-31T15:09:26+00:00

I am having trouble writing data to an excel sheet. My other part of

  • 0

I am having trouble writing data to an excel sheet. My other part of the program will generate an ArrayList of Objects and send it to this loop. This loop reads one object after the other and writes to the Excel sheet.

I know I am missing something. It writes only the last object from the List.

If I try placing this code inside the while loop:

FileOutputStream out = new FileOutputStream(writeExcel);
        writeExtraBook.write(out);
        out.close();

Then it writes only the first record to the file.

Can anyone help me where I am doing wrong

Here is the code that writes the data:

String writeExcel = CONSTANTS.FOW_FILE_PATH;

    FileInputStream writeInput;
    try {
        writeInput = new FileInputStream(writeExcel);

        /** Create a POIFSFileSystem object **/
        POIFSFileSystem mywriteSystem = new POIFSFileSystem(writeInput);
        HSSFWorkbook writeExtraBook = new HSSFWorkbook(mywriteSystem);
        HSSFSheet myExtrasSheet = writeExtraBook.getSheet("FOW");
        HSSFRow extraRow = null;
        HSSFCell extraRowCell = null;
        int lastRowNumber = myExtrasSheet.getLastRowNum();

        Iterator<FoWForm> iter = fowList.iterator();
        while (iter.hasNext()) {
            extraRow = myExtrasSheet.createRow(lastRowNumber + 1);
            FoWForm form = iter.next();
            extraRowCell = extraRow.createCell(0);
            extraRowCell.setCellValue(lastRowNumber + 1);
            extraRowCell = extraRow.createCell(1);
            extraRowCell.setCellValue(form.getFowDesc());
            extraRowCell = extraRow.createCell(2);
            extraRowCell.setCellValue(form.getForCountry());
            extraRowCell = extraRow.createCell(3);
            extraRowCell.setCellValue(form.getMatchId());
            extraRowCell = extraRow.createCell(4);
            extraRowCell.setCellValue(form.getAgainstCountry());

        }
        FileOutputStream out = new FileOutputStream(writeExcel);
        writeExtraBook.write(out);
        out.close();
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:09:27+00:00Added an answer on May 31, 2026 at 3:09 pm

    I suspect this is the problem:

    int lastRowNumber = myExtrasSheet.getLastRowNum();
    ...
    while (iter.hasNext()) {
        extraRow = myExtrasSheet.createRow(lastRowNumber + 1);
    

    You’re only evaluating lastRowNumber once – so on every iteration, you’re calling createRow with the same new row number, which is presumably overwriting the row.

    I suspect you want:

    lastRowNumber++;
    

    within the loop…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble reading and writing QByteArray data to a file. My goal is
I'm quite new to sql and I'm having trouble writing this i have a
Im having some trouble writing a getstring function, this is what I have so
I am having trouble writing the result of my SELECT statement into an excel
I'm having a bit of trouble writing a class that uses generics because this
I'm having some trouble writing a secure WCF data service to be consumed by
I'm having a bit of trouble writing an sql for this scenario. For example
I'm writing a tool that will generate HTML based on JSON data, and puts
I'm having trouble with writing a simple XSLT transform. Here is the XML data:
I am having trouble writing a query. I have been working with UNION on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.