title: How to update cell reference values using Apache POI
body: <p>I am using Apache POI to create new XSSFWorkbook from an existing one, after updating some values. Suppose I have two worksheets (Lets say: worksheet A &amp; B) in my existing workbook. Worksheet B has some cell reference from Worksheet A. IF i modify those cell values of worksheet A and save them as a new workbook, corresponding cell values of worksheet B should be updated too. But it doesn't. How can i update them programmatically? . Thank you.</p>
  
  <p>My code:</p>
  
  <pre><code>public  void createExcel(ClientData cd) throws FileNotFoundException, IOException, InvalidFormatException{
              // create a new file
          double[] dataHolder1= cd.getFinalData1(),  param1 = cd.getRecord1Param();
          double[] dataHolder2 = cd.getFinalData2(), param2 = cd.getRecord2Param();
          double[] ncv = cd.getNcv();
          String[] pname = cd.getName();
              Workbook workbook = new XSSFWorkbook(OPCPackage.open(new FileInputStream("template/mncv.xlsx"))); // or sample.xls
              //CreationHelper createHelper = workbook.getCreationHelper();
              Sheet s=workbook.getSheetAt(0);
  
              int counter = dataHolder1.length + param1.length +param2.length+dataHolder2.length;//+ param1.length + param2.length;
  //            r = s.getRow(0);
  //            r.getCell(0).setCellValue("Param1");
  //            r.getCell(1).setCellValue("Record1");
  //            r.getCell(2).setCellValue("Param2");
  //            r.getCell(3).setCellValue("Record2");
  
              int i;
              for(i=0;i&lt;counter;i++){
                  if(i&lt;param1.length){
                      for(int j=0;j&lt;param1.length;j++){
                          r = s.getRow(i);
                          r.getCell(0).setCellValue(param1[j]);
                          i++;
                      }
                  }else if(i&lt;dataHolder1.length+param1.length &amp;&amp; i&gt;=param1.length){
  
                      for(int j=0;j&lt;dataHolder1.length;j++){
                          r = s.getRow(i);
                          r.getCell(0).setCellValue(dataHolder1[j]);
                          i++;
                      }
  
                  }else if(i&lt;dataHolder1.length+param1.length+param2.length &amp;&amp; i&gt;=dataHolder1.length+param1.length){
                      for(int j=0;j&lt;param2.length;j++){
                          r = s.getRow(i);
                          r.getCell(0).setCellValue(param2[j]);
                          i++;
                      }
                  }else{
                      for(int j=0;j&lt;dataHolder2.length;j++){
                          r = s.getRow(i);
                          r.getCell(0).setCellValue(dataHolder2[j]);
                          i++;
                      }
                  }
  
  //                if(i&lt;=param1.length){
  //                    r.getCell(0).setCellValue(param1[i-1]);
  //                    r.getCell(2).setCellValue(param2[i-1]);
  //
  //                }
                  // r.getCell(0).setCellValue(param1[i]);
                   //r.getCell(3).setCellValue(dataHolder2[i-1]);
                  i--;
              }
              for(int k=0;k&lt;ncv.length;k++){
                  r = s.getRow(i);
                  r.getCell(0).setCellValue(ncv[k]);
                  i++;
              }
  
              s = workbook.getSheetAt(1);
  
              s.getRow(2).getCell(5).setCellValue(pname[0]+" "+pname[1]+" "+pname[2]);
              s.getRow(3).getCell(5).setCellValue(cd.getAge());
              s.getRow(4).getCell(5).setCellValue(cd.getGender());
  
  
   try (FileOutputStream out = new FileOutputStream("workbook.xlsx")) { 
       //WorkbookEvaluator we = new WorkbookEvaluator(workbook); 
  
              workbook.write(out);     
              out.close();
            XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) workbook);
  
          }catch(Exception e){
              System.out.println(e);
          }
  </code></pre>