title: perform operations on excel data sheet using java
body: <p>there are four columns in excel sheet</p>
  
  <ol>
  <li>I need to perform operations on three columns and display the result on the fourth one.</li>
  <li><a href="https://i.stack.imgur.com/xBE2h.png" rel="nofollow noreferrer">Image with data in excel</a></li>
  <li>If I perform B9-D9 then the result is equal to C9.</li>
  <li>when this happens the output should be as "matched".</li>
  <li><p>i need to know how to  access each row and column and perform the  necessary operation on it.
  See if you can help me and let me know if any additional details are required.</p>
  
  <pre><code>package com.infy;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.util.Iterator;
  
  
  
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.apache.poi.ss.usermodel.Workbook;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  
  public class ReconMatch {
      public static void main(String[] args) throws IOException, 
  FileNotFoundException{
          // TODO Auto-generated method stub
          String excelFilePath ="C:/Users/akshay.kuchankar/Documents/demo.xlsx";
          FileInputStream inputStream = new FileInputStream(new 
  File(excelFilePath));
  
          Workbook workbook = new XSSFWorkbook(inputStream);
          Sheet firstSheet = workbook.getSheetAt(0);
          Iterator&lt;Row&gt; iterator = firstSheet.iterator();
  
          while (iterator.hasNext()) {
              Row nextRow = iterator.next();
              Iterator&lt;Cell&gt; cellIterator = nextRow.cellIterator();
  
               while (cellIterator.hasNext()) {
                   Cell cell = cellIterator.next();
  
                   //what should be the basic approach or the syntax to perform the operaiton??
               }
               System.out.println();
            }
            workbook.close();
            inputStream.close();
  
          }
  
      }
  </code></pre>
  
  <hr>
  
  <pre><code> for(int i= 0; i&lt;firstSheet.getRow(0).getCell(0).getNumericCellValue(); i++)
              {
  
                  FGAmount = firstSheet.getRow(1).getCell(1).getNumericCellValue();
                  //  System.out.println(FGAmount);
                  difference = firstSheet.getRow(1).getCell(3).getNumericCellValue();
                  value = FGAmount + difference;
  
              }
                      alconAmount = firstSheet.getRow(1).getCell(2).getNumericCellValue();
  
         //           result = firstSheet.getRow(1).getCell(4).getStringCellValue();
  
          }               
      }
      try {
          if(value== alconAmount){
              firstSheet.getRow(1).getCell(4).setCellValue("Manual Matched");
              System.out.println("matched");
          }                       
  
      } catch (Exception e) {
          e.printStackTrace();
          System.out.println(e);
      }
      // System.out.println(result);
  
       workbook.close();
       inputStream.close();
  </code></pre></li>
  </ol>