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

  • Home
  • SEARCH
  • 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 3284658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:10:44+00:00 2026-05-17T20:10:44+00:00

I am beginner to Apache POI api. I am trying to create excel sheet

  • 0

I am beginner to Apache POI api. I am trying to create excel sheet using arraylist.

My java code is as follows.

HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");
     HSSFCellStyle style = wb.createCellStyle();
        style.setFillForegroundColor(HSSFColor.LIME.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

    HSSFRow row4 = sheet.createRow(4);
    row4.createCell(4).setCellValue("name");
    row4.createCell(5).setCellValue("emailId");
    sheet.autoSizeColumn(5);
    List<Bean> nameList = this.getArrayList();

    Iterator<Bean> nameListIterator = nameList.iterator();


    sheet.autoSizeColumn(5);

    int i=5;
    HSSFRow row = null;


    while(nameListIterator.hasNext())
    {
        Bean bean = nameListIterator.next();

        row = sheet.createRow(i);
        row.createCell(4).setCellValue(bean.getName());


        row.createCell(5).setCellValue(bean.getMailId());
        i++;
    }

The arraylist is as follows:

List<Bean> beanList = new ArrayList<Bean>();
    beanList.add(new Bean("Amy","g@y.comrtyrtyrtyrtyrtyr"));
    beanList.add(new Bean("Joan","p@y.comrtyrtyrtyrtyrtyr"));
    beanList.add(new Bean("Megan","r@y.comrtyrtyrtyrtyrtyr"));
    beanList.add(new Bean("Joe","m@y.comrtyrtyrtyrtyrtyr"));
    beanList.add(new Bean("Febi","j@y.comrtyrtyrtyrtyrtyr"));

When the excel sheet is generated, the column does not fit to the size of the content correctly. I searched Google related to this problem and found

sheet.autoSizeColumn(5);

is the solution to my problem. I added as in the code above, but still the problem persists. Am I using it correctly?

Is there any other solution?

Please help

Thanks in advance

P.s: I am using Apache Poi 3.6

  • 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-17T20:10:45+00:00Added an answer on May 17, 2026 at 8:10 pm

    You just need to move the call to

    sheet.autoSizeColumn(5);
    

    to a point in your code after the data has been added, so right after your while loop should work.

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

Sidebar

Related Questions

import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.FileInputStream; import java.lang.Iterable; public class
Im a complete beginner with Apache re-writes. Im trying to get example.com/forum to be
I am a complete beginner trying to develop for FCKeditor so please bear with
As a complete beginner with no programming experience, I am trying to find beautiful
I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the
I am developing a website using PHP and Apache. I wanna turn my URLs
I'm a beginner java developer and i'm not very confident with java world tools.
Beginner in JS :) needs an explanation of code piece from Crockford's book ,
can someone pls tell me how can i execute my HelloWorld.java in apache hadoop
I'm very new to this. Why is openssl_pkey_new() returning false? I am using XAMPP

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.