EasyXLS http://forum.easyxls.com/ |
|
Calculate formulas http://forum.easyxls.com/viewtopic.php?f=5&t=16 |
Page 1 of 1 |
Author: | Andreas [ Thu Jun 01, 2006 9:59 pm ] |
Post subject: | Calculate formulas |
Will EasyXLS allow me to create a spreadsheet in memory, either from scratch or loaded from a file, change cell values (including formulas), and calculate the spreadsheet? |
Author: | exari [ Fri Jun 02, 2006 11:23 am ] |
Post subject: | Formula computation |
Here is the C#.NET sample code to change cell values or formulas and to recalculate the spreadsheet: ----------------------------- Creating an worksheet in the memory ExcelDocument xls = new ExcelDocument(); ExcelWorksheet xlsWorksheet = new ExcelWorksheet("Sheet1"); xls.easy_addWorksheet(xlsWorksheet); // Adding some data to the worksheet ExcelTable xlsTable = xlsWorksheet.easy_getExcelTable(); xlsTable.easy_getCell(0,0).setValue("1"); xlsTable.easy_getCell(1,0).setValue("2"); xlsTable.easy_getCell(2,0).setValue("3"); <b>// Adding a formula xlsTable.easy_getCell(3,0).setValue("=SUM(A1:A3)"); // Calling the method used to compute the formulas String sError = xlsWorksheet.easy_computeFormulas(xls, true);</b> if (sError.Length == 0) Console.WriteLine("Formulas computed successfully"); else Console.WriteLine("Error computing formulas! Error: " + sError); <b>// Displaying the result of the formula Console.WriteLine("The result of the formula entered at position A4 is: " + xlsTable.easy_getCell(3,0).getFormulaResultValue());</b> // Writting the excel file. xls.easy_WriteExcelFile("C:\\Samples\\FormulaResult.xls"); |
Author: | lelia [ Wed Aug 22, 2007 2:15 am ] |
Post subject: | |
I have the following problem: This example works OK while I use integers as data (in cells A1:A3). Then I tried to change them to floats ( xlsTable.easy_getCell(0,0).setValue("1.5"); or xlsTable.easy_getCell(0,0).setValue("1,5"); I tried both variants) I got "#VALUE!" as a result of xlsTable.easy_getCell(3,0).getFormulaResultValue();. However sError was equal to string.Empty. How can I calculate formulas on floats? |
Author: | claudiu [ Fri Aug 24, 2007 8:32 am ] |
Post subject: | |
In case you changed the data type, you need to be sure that the datatype of the cells is NUMERIC xlsTable.easy_getCell(0,0).setValue("1.5"); xlsTable.easy_getCell(0,0).setDataType(DataType.NUMERIC); Please let us know if this solved your problem. |
Author: | lelia [ Wed Aug 29, 2007 2:47 am ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Post subject: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
Unfortunatelly it doesn't Last time 1 tried the following code
The result in 1.txt was the following
But then I opened 1.xls everything was OK there
Do you have any ideas why is it so in my case? I hope you can help me to solve this problem. PS: if i change 1,5 to 1 in A1 cell everything is OK The result I get in that case is
PPS: I tried to test this functional also by opening a correct xls file. The result was the same
|
Author: | claudiu [ Wed Aug 29, 2007 5:34 am ] |
Post subject: | |
Please use "."(dot) instead of "," (comma) for floats. This should solve the problem. xlsTable.easy_getCell(0,0).setValue("1.5"); |
Author: | lelia [ Wed Aug 29, 2007 7:24 am ] | |||||||||||||||||||||||||||
Post subject: | ||||||||||||||||||||||||||||
On my computer default separator for floats is comma. For example correct number in excel is 1,5. But I tried "." The result is
Also threre is nothing!!! in cell A1 in result excel file. There is NO! exception during execution but in console window i can see the following
|
Author: | claudiu [ Fri Aug 31, 2007 5:41 am ] |
Post subject: | |
For the moment being the only accepted format is the one with the dot as the default separator for floats. To change the default settings for your computer go to Control Panel -> Regional Options -> Numbers. Sorry for the inconvenience. |
Page 1 of 1 | All times are UTC - 4 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |