Friday, October 30, 2015

Solution for larger numbers which get read in exponential format from excel.

When you try to read excel in JAVA and come across cells which have Numbers greater than 12 digits, it will automatically get converted in Exponential format.

Example: 104009000084 gets converted to 1.04009000084E11

Now even if you change the cell format from Number to Text, it still considers it as Number and converts it to exponential format while reading the file in JAVA.

Solution 1:
Write sign ' before the number in excel sheet.

Solution 2:
Delete the value from excel , change the format from Number to Text and then rewrite the value back to excel.




Tuesday, October 27, 2015

POI API for writing data from excel file to a text file.

Many times you will come across situations, wherein you will need to read data from excel files and do some processing.

POI API comes to the rescue here :)

Download the latest POI jar file and add it to your project library.

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

public class ConvertFile 
{
   public static void main(String[] args) 
   {
      System.out.println("Start of Program");
      try
      {
FileInputStream file = new FileInputStream(new File("D:\\Test_Data_Automation.xls"));

//Get the workbook instance for XLS file 
HSSFWorkbook workbook = new HSSFWorkbook(file);

//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(2);

//Get iterator to all the rows in current sheet
Iterator<Row> rowIterator = sheet.iterator();

String fileName = "";
PrintWriter writer = null;

        while(rowIterator.hasNext())
         {
            Row row = rowIterator.next();
       
            //For each row, iterate through each columns
            Iterator<Cell> cellIterator = row.cellIterator();
             
            try{
                 writer = new PrintWriter("D:\\Output_Data.txt", "UTF-8");
            }catch(Exception ex){ex.printStackTrace();}
                          
            while(cellIterator.hasNext()) 
            {
               Cell cell = cellIterator.next();
                       
            if(cell.getRowIndex() > 3)      //Start reading from the 3rd row.
            {
               switch(cell.getCellType()) 
               {
                  case Cell.CELL_TYPE_BOOLEAN:
                  System.out.print(cell.getBooleanCellValue() + "\t\t");
                  writer.println(String.valueOf(cell.getBooleanCellValue()));
                  break;
                  
                   case Cell.CELL_TYPE_NUMERIC:
                  System.out.print(cell.getNumericCellValue() + "\t\t");
                  writer.println(String.valueOf(cell.getNumericCellValue()));
                  break;
                   
                   case Cell.CELL_TYPE_STRING:
                  System.out.print(cell.getStringCellValue() + "\t\t");
                  writer.println(String.valueOf(cell.getStringCellValue()));
                  break;
                   
                   case Cell.CELL_TYPE_FORMULA:
                  cellValue=String.valueOf(cell.getStringCellValue());
                  break;
                   
                   case Cell.CELL_TYPE_ERROR:
                  cellValue=String.valueOf(cell.getStringCellValue());
                  break;
                  }
            }
             }
             
             try{
             System.out.println("Close the file");
                 writer.close();
             }catch(Exception ex){ex.printStackTrace();}
         }

         System.out.println("End of Program");

     }
     catch(Exception ex) {ex.printStackTrace();}
   }
}   //End of Main


Some Important syntax->
1) To read any row apart from the current row, use the following.
     Row nextRow = sheet.getRow(row.getRowNum() + 1);
     Row prevRow = sheet.getRow(row.getRowNum() - 1);
     Row next2Row = sheet.getRow(row.getRowNum() + 2);
     Row prev2Row = sheet.getRow(row.getRowNum() - 2);
     etc.

2) To read any column in any particular row, use the following.
     row.getCell(1);
     row.getCell(7);
     row.getCell(11);
     etc.

Tuesday, October 6, 2015

How to check EPF (Employee Provident Fund) balance

How much money goes in the PF (Provident Fund) Account?
  1. Employee Contribution : 12% of your Basic
  2. Employer Contribution  : 12%  of your Basic (8.33% goes to EPS)
  3. Interest on both the contribution.

What is EPS?

EPF = Employee Pension Scheme.

The purpose of the scheme is to provide for
1) Superannuation Pension:Member who has rendered eligible service of 20 years and retires on attaining the age of 58 years.
2) Retiring Pension:member who has rendered eligible service of 20 years and retires or otherwise ceases to be in employment before attaining the age of 58 years.
3) Permanent Total Disablement Pension 4) Short service Pension: Member has to render eligible service of 10 years and more but less than 20 years.



Steps to check PF Online:

1) Get your PF Account Number - It is normally mentioned on your payslip, if not check with your HR team.

It will look like MH / 98765 / 1234567

2) Go to EPFO website - http://epfindia.com/site_en/KYEPFB.php

3) Click on the following link -> "Click here to know Your PF Balance"




4) Select your State and Office Name as shown below.




5) Enter all the details as shown below and click on "Submit" Button.

First 2 text fields will be populated automatically.

You can keep the 4th text blank, if you dont know the extension number.




6) You will now receive an SMS from EPFO.

In the SMS, 2 amounts will be mentioned "EE Amount" and "ER Amount".

EE Amt = Employee Balance

ER Amt = Employer Balance
 
Home