EasyXLS
http://forum.easyxls.com/

Calculating fractions and or percentages
http://forum.easyxls.com/viewtopic.php?f=5&t=91
Page 1 of 1

Author:  olle [ Fri Aug 31, 2007 6:33 am ]
Post subject:  Calculating fractions and or percentages

I have a sheet in which allot of percentages are used. I constantly got the result #value! when I requested the formulaResultValue. I played with changing the decimal sepperator from , to . on my system, I switched from percentage to numbers so that 12% would be represented as 0.12 but nothing works. I then made a smaller test case as follow for which I get #N/A!. Any ideas?

Code:
                ExcelDocument xls2 = new ExcelDocument(2);
                xls2.easy_getSheetAt(0).setSheetName("First tab");
                ExcelTable xlsFirstTable2 = ((ExcelWorksheet)xls2.easy_getSheetAt(0)).easy_getExcelTable();
                xlsFirstTable.easy_getCell("A1").setValue("=1/2");
                xlsFirstTable.easy_getCell("A1").setDataType(EasyXLS.Constants.DataType.AUTOMATIC);
                ((ExcelWorksheet)xls2.easy_getSheetAt(0)).easy_computeFormulas(xls2, true);
                string s2 = xlsFirstTable.easy_getCell("A1").getFormulaResultValue();

Author:  claudiu [ Mon Sep 03, 2007 6:19 am ]
Post subject: 

I reproduced your test (fixing the errors) and I came up with this which worked just fine. My default systems settings for decimal separator is . (dot)

Please, try it and let me know if this worked for you. If not, send the file you are working with to support@easyxls.com (remove the confidential content) and I will have a look at it.

Code:
using System;
using EasyXLS;
using EasyXLS.Constants;

public class Test
{


   [STAThread]
   static void Main()
   {
      Console.WriteLine("Test\n-----------\n");
       
        ExcelDocument xls = new ExcelDocument(2);
        xls.easy_getSheetAt(0).setSheetName("First tab");
        ExcelTable xlsFirstTable = ((ExcelWorksheet)xls.easy_getSheetAt(0)).easy_getExcelTable();
        xlsFirstTable.easy_getCell("A1").setValue("=12%");
        xlsFirstTable.easy_getCell("A1").setDataType(EasyXLS.Constants.DataType.AUTOMATIC);
        ((ExcelWorksheet)xls.easy_getSheetAt(0)).easy_computeFormulas(xls, true);
        string s2 = xlsFirstTable.easy_getCell("A1").getFormulaResultValue();

        Console.WriteLine("Writing file C:\\Samples\\Test.xls.");
        xls.easy_WriteExcelFile("C:\\Samples\\Test.xls");

        //Confirm generation
        String sError = xls.easy_getError();
        if (sError.Equals(""))
            Console.Write("\nFile successfully created. Press Enter to Exit...");
        else
            Console.Write("\nError encountered: " + sError + "\nPress Enter to Exit...");

        //Dispose memory
        xls.Dispose();

        Console.ReadLine();
    }
}

Page 1 of 1 All times are UTC - 4 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/