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 7945879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:59:40+00:00 2026-06-04T00:59:40+00:00

i am trying to get the record based on some unique value. Example; It

  • 0

i am trying to get the record based on some unique value.

Example; It there is a table of values with emp name, emp id, emp address, i want to fetch the record based on the emp id.

this the code i have tried also this code reads data from the file not from beginning.

package org.xlsx.read;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 * 015 * @author giftsam 016
 */
public class ExcelSheetReader {

    /**
     * 021 * This method is used to read the data's from an excel file. 022 * @param
     * fileName - Name of the excel file. 023
     */
    private void readExcelFile(String fileName) {
        /**
         * Create a new instance for cellDataList
         */
        List cellDataList = new ArrayList();
        try {
            /**
             * 033 * Create a new instance for FileInputStream class 034
             */
            FileInputStream fileInputStream = new FileInputStream(fileName);

            /**
             * Create a new instance for POIFSFileSystem class
             */
            POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);

            /*
             * 043 * Create a new instance for HSSFWorkBook Class 044
             */
            HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
            HSSFSheet hssfSheet = workBook.getSheetAt(0);

            /**
            * Iterate the rows and cells of the spreadsheet 050 
             * * to get
             * all the datas
             */
            Iterator rowIterator = hssfSheet.rowIterator();

            while (rowIterator.hasNext()) {
                HSSFRow hssfRow = (HSSFRow) rowIterator.next();
                Iterator iterator = hssfRow.cellIterator();
                List cellTempList = new ArrayList();
                while (iterator.hasNext()) {
                    HSSFCell hssfCell = (HSSFCell) iterator.next();
                    cellTempList.add(hssfCell);
                }
                cellDataList.add(cellTempList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        /**
         * Call the printToConsole method to print the cell data in the console.
         */
        printToConsole(cellDataList);
    }

    /**
     * This method is used to print the cell data to the console.
     * 
     * @param cellDataList
     *            - List of the data's in the spreadsheet.
     */
    private void printToConsole(List cellDataList) {
        for (int i = 0; i < cellDataList.size(); i++) {
            List cellTempList = (List) cellDataList.get(i);
            for (int j = 0; j < cellTempList.size(); j++) {
                HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
                String stringCellValue = hssfCell.toString();
                System.out.print(stringCellValue + "\t");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        String fileName = "D:/workspace/ReadExlsx/xlsx/Access_Control_Report_01-04-2012to30-04-2012.xls";
        new ExcelSheetReader().readExcelFile(fileName);
    }
}

this code prints out put like this.

292 Manikiruban Jaganathan  001 Esg     05/04/2012  09:11:28    19:06:06        
292 Manikiruban Jaganathan  001 Esg     06/04/2012  09:01:07    19:02:37        
292 Manikiruban Jaganathan  001 Esg     09/04/2012  09:02:08    19:39:29        
292 Manikiruban Jaganathan  001 Esg     10/04/2012  09:13:20    18:54:05        
292 Manikiruban Jaganathan  001 Esg     11/04/2012  09:31:55    18:33:03

my excel sheet looks like this :

Sling Media Pvt Ltd                                             
First and Last Record Details Report From 01/04/2012 to 30/04/2012                                              
Report Prepared on: 10/05/2012 at 12:51                                             

EmpID   EmpName SiteCode    Department  Type    Date    First   Last    Location                
1   Kr Veerappan    123 Hardware Team       02/04/2012  10:30:39    20:23:14                    
1   Kr Veerappan    123 Hardware Team       03/04/2012  09:46:01    19:58:16                    
1   Kr Veerappan    123 Hardware Team       04/04/2012  10:06:26    19:58:31                    
1   Kr Veerappan    123 Hardware Team       05/04/2012  11:38:51    19:32:17                    
1   Kr Veerappan    123 Hardware Team       06/04/2012  10:43:06    21:02:06                    
1   Kr Veerappan    123 Hardware Team       09/04/2012  11:02:32    22:05:14                    
1   Kr Veerappan    123 Hardware Team       10/04/2012  10:49:41    19:07:48                    
1   Kr Veerappan    123 Hardware Team       11/04/2012  10:16:42    20:30:13                    
1   Kr Veerappan    123 Hardware Team       12/04/2012  10:15:54    19:54:51                    
1   Kr Veerappan    123 Hardware Team       13/04/2012  10:18:30    19:05:55                    
1   Kr Veerappan    123 Hardware Team       18/04/2012  10:52:37    18:50:36                    
1   Kr Veerappan    123 Hardware Team       19/04/2012  10:24:59    20:29:59                    
1   Kr Veerappan    123 Hardware Team       20/04/2012  10:29:47    18:58:23                    
1   Kr Veerappan    123 Hardware Team       23/04/2012  10:24:31    20:11:29                    
1   Kr Veerappan    123 Hardware Team       24/04/2012  10:13:18    19:05:25                    

thanks
Antony

  • 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-06-04T00:59:41+00:00Added an answer on June 4, 2026 at 12:59 am

    Suppose you want to fetch the employee whose eid = 1 , then you can put a check while you print it on console.
    Since you dont know which row contains the eid=1 .So you have to parse each row.

    The index of eid is 2 as it seems from the output.

    So following changes can be performed.

    private void printToConsole(List cellDataList) {
            for (int i = 0; i < cellDataList.size(); i++) {
                List cellTempList = (List) cellDataList.get(i);
                if((HSSFCell) cellTempList.get(2).toString().equals("1"))
                {
                for (int j = 0; j < cellTempList.size(); j++) {
    
                    HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
                    String stringCellValue = hssfCell.toString();
    
                    System.out.print(stringCellValue + "\t");
                }
                }
                else { 
                 i++;
                }
                System.out.println();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert a record into a table using Linq but get
I am trying to update my table 1 with some field value from table
I'm trying to update a table based on the sum of values from another
I am new to Nhibernate, I am trying to get record by ID and
I'm trying to get the top N records for each unique row of data
I'm trying to get the top N records (when ordered by some column X),
I am trying to get all the prime(row) numbered records from my table.Can someone
Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to create a SQL statement to find the matching record based on
I'm trying to subset the records in a numpy.recarray based on the common values

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.