value in cell (computed by excel formula)

Last post 07-03-2009, 4:19 AM by Amjad Sahi. 3 replies.
Sort Posts: Previous Next
  •  07-02-2009, 9:10 PM 186668

    value in cell (computed by excel formula) Java

    Hi,

    In my excel worksheet, there is a formula attached with a cell.

    However, when i use the method of com.aspose.cells.Cell.getValue() , it returns 0.0 where the cell actually got value with it.

    Sample:

    private Workbook book = new Workbook();
    Cells cell =
    book.getWorksheets().getSheet("SHEETA").getCells();

    cell.getCell("J312").getFormula();  // return SUM(J7:J311)
    cell.getCell("J312").getValue(); // return 0.0

    Any idea?

    Thanks.

     
  •  07-03-2009, 1:46 AM 186699 in reply to 186668

    Re: value in cell (computed by excel formula)

    Attachment: Present (inaccessible)

    Hi,

     

    Thank you for considering Aspose.

     

    Well, I checked your issue with the latest version of Aspose.Cells for Java and it works fine. Following is my sample code:

     

    Workbook workbook = new Workbook();

    workbook.open("C:\\Excels\\book1.xls");

                

    Cells cell = workbook.getWorksheets().getSheet("SHEETA").getCells();

     

    System.out.println(cell.getCell("J312").getFormula());          

    System.out.println(cell.getCell("J312").getValue());

     

    Please try the attached latest version and if you still face any problem, please share your template file and we will check it soon.

     

    If you are applying the formula at runtime to your template file, please call Workbook.calcualteFormula() before getting the value of the cell.

     

    Thank You & Best Regards,


    Nausherwan Aslam
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  07-03-2009, 3:01 AM 186723 in reply to 186699

    Re: value in cell (computed by excel formula)

    Attachment: Present (inaccessible)

    Hi,

    It does not work succesfully in my environment.

    I tried it with both version of Aspose.Cells (v2.0.1.24 and v2.0.1.25) where i get the v2.0.1.25 from thread :  http://www.aspose.com/community/forums/thread/186516.aspx, but still it failed.

    Pls find my code below and the attached template files.

    Code:

    Cells cell = book.getWorksheets().getSheet("Sheet1").getCells();
    for(int i=1;i<22;i++){ 
       cell.getCell("A"+(i+1)).setValue(3);
    }
    System.
    out.println(cell.getCell("A23").getFormula());
    System.out.println(cell.getCell("A23").getValue());

    Result:
    =SUM(A2:A22)
    0.0

    Thanks.

     
  •  07-03-2009, 4:19 AM 186735 in reply to 186723

    Re: value in cell (computed by excel formula)

    Hi,

    If you are dynamically add/change the values of those cells which are the part of a formula, you need to call Workbook.calculateFormula().

    Please add a line to your code:

    Code:

    Cells cell = book.getWorksheets().getSheet("Sheet1").getCells();
    for(int i=1;i<22;i++){ 
       cell.getCell("A"+(i+1)).setValue(3);
    }

    book.calculateFormula();
    System.
    out.println(cell.getCell("A23").getFormula());
    System.out.println(cell.getCell("A23").getValue());

     

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
View as RSS news feed in XML