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,010 points
4,261 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,420 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,670 points
13,365 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
3,092 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
321 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,420 points
541 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,420 points
1,673 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,420 points
2,693 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,420 points
1,463 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,420 points
721 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