473,847 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formulas/converting from JS?

Hi Guys,

I have a program which converts Excel spreadsheets to Javascript and
allows interactivity. However it can't convert it to PHP, which is
obviously better for users to view (in case J/S is turned off).

How would I go about converting some of this created code (example JS
below), or is there an easier way to get PHP to do the calculations
itself? I am aware of an excel-server product but this is too expensive
and doesnt actually produce any code.

I'm not suggesting someone convert this (also as its only an example),
but the code seems quite complicated for a junior PHP person. Any
thoughts on what I could do?

Thanks

(code created by spreadsheet converter)
<script language="javas cript">

var co = new Object;
function recalc_onclick( ctl) {
if (true) {

co.pA7D=eeparse Float(document. formc.pA7D.valu e);calc(co);doc ument.formc.pA7 E.value=eedispl ayFloat(co.pA7E );
};};

var eeisus=0;var eetrue="TRUE";v ar eefalse="FALSE" ;var eedec=".";var
eeth=",";var eedecreg=new RegExp("[.]","g");var eethreg=new
RegExp(",","g") ;

var row1xD2D5=new Array(4);for(va r jj=0;jj<4;jj++) {row1xD2D5[jj]=0};var
row1xE2E5=new Array(4);for(va r
jj=0;jj<4;jj++) {row1xE2E5[jj]=0};function calc(data){var
cA7D=data.pA7D; row1xD2D5[0]=(10);row1xE2E5[0]=(1);row1xD2D5[1]=(20);row1xE2E5[1]=(2);row1xD2D5[2]=(30);row1xE2E5[2]=(3);row1xD2D5[3]=(40);row1xE2E5[3]=(4);var
cA7E=(lookup3vv ((cA7D),row1xD2 D5,0,3,row1xE2E 5,0,3));data.pA 7E=cA7E;};

function myIsNaN(x){retu rn(isNaN(x)||(t ypeof
x=='number'&&!i sFinite(x)));}; function
eeparseFloat(st r){str=String(s tr).replace(eed ecreg,".");var
res=parseFloat( str);if(isNaN(r es)){return 0;}else{return
res;}};function eedisplayFloat( x){if(myIsNaN(x )){return
Number.NaN;}els e{return String(x).repla ce(/\./g,eedec);}};fun ction
lookup3vv(key,k vect,kfrom_star t,kto_start,vve ct,vfrom_,vto_) {var
current=0;var from_=kfrom_sta rt;var
to_=kto_start+1 ;while(true){cu rrent=(from_+to _)>>1;if(kvect[current]==key)break;if( from_==to_-1)break;if(kvec t[current]<key){from_=cur rent;}else{to_= current;}};whil e(current<kto_s tart){if(kvect[current]==kvect[current+1]){current++;}el se{break;};};if (key<kvect[current])return
Number.NaN;retu rn vvect[vfrom_+current-kfrom_start]};
</script>

Feb 2 '06 #1
1 2159

"UKuser" <sp********@yah oo.co.uk> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi Guys,

I have a program which converts Excel spreadsheets to Javascript and
allows interactivity. However it can't convert it to PHP, which is
obviously better for users to view (in case J/S is turned off).

How would I go about converting some of this created code (example JS
below), or is there an easier way to get PHP to do the calculations
itself? I am aware of an excel-server product but this is too expensive
and doesnt actually produce any code.

I'm not suggesting someone convert this (also as its only an example),
but the code seems quite complicated for a junior PHP person. Any
thoughts on what I could do?
you would probably need to start with this (below), wich I found in the user
notes of the CHM manual of COM and .NET (Windows) section.:
you will also need to write a tokenizer and recursive-descent parser to
parse the function strings, which can be pretty involved. maybe try using
strtok?
this may be why they charge money for the product. You will need to write
at least a BNF grammar for the formula language, and it can be tricky
getting this right, especially with all those optional parameters. And excel
has a lot of functions, so the grammar is going to be at >2 pages long. A
railroad diagram may also help the process.
....and then again there is a simpler way to do it if they are all your
spreadsheets and you know them by heart.

If you want to search an Excel file and don't connect with ODBC, you can try
the function I provide. It will search a keyword in the Excel find and
return its sheet name, text, field and the row which found the keyword.
<?php
// The example of print out the result
$result = array();
searchEXL("C:/test.xls", "test", $result);
foreach($result as $sheet => $rs){
echo "Found at $sheet";

echo "<table width=\"100%\" border=\"1\"><t r>";

for($i = 0; $i < count($rs["FIELD"]); $i++)
echo "<th>" . $rs["FIELD"][$i] . "</th>";

echo "</tr>";

for($i = 0; $i < count($rs["TEXT"]); $i++) {
echo "<tr>";

for($j = 0; $j < count($rs["FIELD"]); $j++)
echo "<td>" . $rs["ROW"][$i][$j] . "</td>";

echo "</tr>";
}
echo "</table>";
}
/**
* @param $file string The excel file path
* @param $keyword string The keyword
* @param $result array The search result
*/
function searchEXL($file , $keyword, &$result) {
$exlObj = new COM("Excel.Appl ication") or Die ("Did not connect");
$exlObj->Workbooks->Open($file);
$exlBook = $exlObj->ActiveWorkBook ;
$exlSheets = $exlBook->Sheets;

for($i = 1; $i <= $exlSheets->Count; $i++) {
$exlSheet = $exlBook->WorkSheets($i) ;

$sheetName = $exlSheet->Name;

if($exlRange = $exlSheet->Cells->Find($keyword) ) {
$col = 1;
while($fields = $exlSheet->Cells(1, $col)) {
if($fields->Text == "")
break;

$result[$sheetName]["FIELD"][] = $fields->Text;
$col++;
}

$firstAddress = $exlRange->Address;
$finding = 1;
$result[$sheetName]["TEXT"][] = $exlRange->Text;

for($j = 1; $j <= count($result[$sheetName]["FIELD"]); $j++) {
$cell = $exlSheet->Cells($exlRang e->Row ,$j);
$result[$sheetName]["ROW"][$finding - 1][$j - 1] = $cell->Text;
}
while($exlRange = $exlRange->Cells->Find($keyword) ) {
if($exlRange->Address == $firstAddress)
break;

$finding++;
$result[$sheetName]["TEXT"][] = $exlRange->Text;

for($j = 1; $j <= count($result[$sheetName]["FIELD"]); $j++) {
$cell = $exlSheet->Cells($exlRang e->Row ,$j);
$result[$sheetName]["ROW"][$finding - 1][$j - 1] = $cell->Text;
}

}

}

}

$exlBook->Close(false) ;
unset($exlSheet s);
$exlObj->Workbooks->Close();
unset($exlBook) ;
$exlObj->Quit;
unset($exlObj);
}
?>
For more information, please visit my blog site (written in Chinese)
http://www.microsmile.idv.tw/blog/index.php?p=77


Thanks

(code created by spreadsheet converter)
<script language="javas cript">

var co = new Object;
function recalc_onclick( ctl) {
if (true) {

co.pA7D=eeparse Float(document. formc.pA7D.valu e);calc(co);doc ument.formc.pA7 E.value=eedispl ayFloat(co.pA7E );
};};

var eeisus=0;var eetrue="TRUE";v ar eefalse="FALSE" ;var eedec=".";var
eeth=",";var eedecreg=new RegExp("[.]","g");var eethreg=new
RegExp(",","g") ;

var row1xD2D5=new Array(4);for(va r jj=0;jj<4;jj++) {row1xD2D5[jj]=0};var
row1xE2E5=new Array(4);for(va r
jj=0;jj<4;jj++) {row1xE2E5[jj]=0};function calc(data){var
cA7D=data.pA7D; row1xD2D5[0]=(10);row1xE2E5[0]=(1);row1xD2D5[1]=(20);row1xE2E5[1]=(2);row1xD2D5[2]=(30);row1xE2E5[2]=(3);row1xD2D5[3]=(40);row1xE2E5[3]=(4);var
cA7E=(lookup3vv ((cA7D),row1xD2 D5,0,3,row1xE2E 5,0,3));data.pA 7E=cA7E;};

function myIsNaN(x){retu rn(isNaN(x)||(t ypeof
x=='number'&&!i sFinite(x)));}; function
eeparseFloat(st r){str=String(s tr).replace(eed ecreg,".");var
res=parseFloat( str);if(isNaN(r es)){return 0;}else{return
res;}};function eedisplayFloat( x){if(myIsNaN(x )){return
Number.NaN;}els e{return String(x).repla ce(/\./g,eedec);}};fun ction
lookup3vv(key,k vect,kfrom_star t,kto_start,vve ct,vfrom_,vto_) {var
current=0;var from_=kfrom_sta rt;var
to_=kto_start+1 ;while(true){cu rrent=(from_+to _)>>1;if(kvect[current]==key)break;if( from_==to_-1)break;if(kvec t[current]<key){from_=cur rent;}else{to_= current;}};whil e(current<kto_s tart){if(kvect[current]==kvect[current+1]){current++;}el se{break;};};if (key<kvect[current])return
Number.NaN;retu rn vvect[vfrom_+current-kfrom_start]};
</script>

Feb 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2805
by: Scott Castillo | last post by:
Looking for a decent source that has some examples of column formulas as well as a list of column formula functions that can be used and how to use them. Hard time finding something online. Any suggestions or references would be greatly appreciated. Fairly new to this. Thanks
1
1558
by: Sergio | last post by:
Hi, someone knows a place to find the relations formulas for N-Trees? Like in a binary tree if you want the father for some node with index i you just do FATHER = i/N (rounding down) for N-Trees that would be FATHER = (i+N-2)/N (rounding down)
4
2252
by: Sehri | last post by:
Hi all, I have just started developing a math companion tool with VS2005 and I just ran into a problem when trying to add the description of a formula. Doed anyone know how can I add math formulas and math characters in .NET? Maybe this is the same for everywhere, I just don't know the answer. I appreciate your help. Thanks, Sehri
3
2811
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula value into a cell. BUT this is where it comes "complex".
3
1266
by: neil | last post by:
Has anyone had experience programming with functions or formulas that occasionally change? We're working on a pricing app and it would be straight-forward enough to build it with a known formula (price = a+b+c/d), but we have to account for business conditions that change the formula. Does anyone know how to do this without recompiling? Thanks.
6
3009
by: Martien van Wanrooij | last post by:
Hi all, I have been looking in some forums etc. but cannot find what I would like. I need some financial formulas for a site related to some mortgage issues. Unfortunately the specifications have been supplied to me be an excel sheet so it is quite tricky to find out how the formulas that are used have been made. To give some examples: I would need a formula for the future value of savings after x years when you have already an amount...
1
1760
by: Brian P. Hammer | last post by:
All - I have a project that has a bunch of formulas. I would like to store each of the formulas in a SQL and then load them and have my app execute it. The problem I see is that a Dataset would return the formula as a string and not as a result. Anyone have an idea on how I could accomplish this? Example: If I wanted to store ((5+15)-9)*10 in SQL. I want to display the answer 111 in a text box and not ((5+15)-9)*10 Thanks, Brian
11
1690
by: rob | last post by:
I have the following scenario. A user requests some math calculations from a server. The data and a library of basic formulas reside on the server. Now the user should be able to create more complex formulas based on the basic built in formulas as well as other complex formulas that the user created himself. These formulas will be either stored on the server or client and will be applied to the data on the server. Some of the formulas will...
4
1791
by: John Brock | last post by:
I have a .NET application that, among other things, creates Excel workbooks, and I have run into a very strange problem involving formulas on one worksheet that reference values on another worksheet. The text I write into, let's say, cell A25 on Sheet1 (using .NET) looks something like this: =VLOOKUP(RC,'Sheet2'!A:X,6,FALSE) On the completed workbook this turns into:
0
9892
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9734
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10995
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10654
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9493
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7888
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7061
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5915
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.