How to get columns from Excel files using Apache POI

0 votes
I need to extract values from a column of an Excel file so that I may perform some statistical analysis. When one has to iterate over rows, the Apache POI module works well for reading from Excel files. However, neither the API (link text) nor a google search turned up anything regarding accessing columns.  Without picking up individual columns, the only other option is to iterate over rows and columns to get the values and compare one at a time, which doesn't sound like it would be very time-efficient. I need to get the maximum and minimum values of various columns so that I can generate random numbers using these values.

Any suggestions on how to solve this issue?
Oct 18, 2022 in Others by Kithuzzz
• 38,000 points
5,288 views

1 answer to this question.

0 votes

The only way to see all the values in a column in an Excel file is to look at each row individually because Excel files are row oriented rather than column based. The fact that cells in a column are not stored together means that there is no faster way to access the columns.

Change your code like this:

List<Double> values = new ArrayList<Double>();
for(Row r : sheet) {
   Cell c = r.getCell(columnNumber);
   if(c != null) {
      if(c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
         valuesadd(c.getNumericCellValue());
      } else if(c.getCellType() == Cell.CELL_TYPE_FORMULA && c.getCachedFormulaResultType() == Cell.CELL_TYPE_NUMERIC) {
         valuesadd(c.getNumericCellValue());
      }
   }
}
answered Oct 18, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
14,040 views
0 votes
1 answer

How to open .xlsx files in MS Excel from VS Code?

Hello, to open xlxs files, or files ...READ MORE

answered Feb 17, 2022 in Others by gaurav
• 23,260 points
4,226 views
0 votes
1 answer

How to get landmarks from current location using google map in iphone?

You can achieve this by saving several ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
515 views
0 votes
1 answer

Excel: How to merge two columns into one (from different sheets or separated columns)

This equation is completely adjustable. Your two ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 63,600 points
878 views
0 votes
1 answer

Convert PDF to Excel in Java

You can convert a PDF document to ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
2,256 views
0 votes
1 answer

What is the better API to Reading Excel sheets in java - JXL or Apache POI

Here are the things where both APIs ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
3,421 views
0 votes
1 answer

Apache POI. Setup data filters in Excel

It's already enabled in Apache POI 3.7. ...READ MORE

answered Oct 21, 2022 in Others by narikkadan
• 63,600 points
2,088 views
0 votes
1 answer

How to create page borders using Apache POI in excel files with Java?

Microsoft Excel cannot do this. Libreoffice Calc ...READ MORE

answered Dec 13, 2022 in Others by narikkadan
• 63,600 points
1,053 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP