Reply to topic  [ 2 posts ] 
Calculating fractions and or percentages 
Author Message

Joined: Fri Aug 31, 2007 6:30 am
Posts: 1
Reply with quote
Post 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();


Fri Aug 31, 2007 6:33 am
Profile

Joined: Fri Aug 24, 2007 5:58 am
Posts: 5
Reply with quote
Post 
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();
    }
}


Mon Sep 03, 2007 6:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.