473,326 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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="javascript">

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

co.pA7D=eeparseFloat(document.formc.pA7D.value);ca lc(co);document.formc.pA7E.value=eedisplayFloat(co .pA7E);
};};

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

var row1xD2D5=new Array(4);for(var jj=0;jj<4;jj++){row1xD2D5[jj]=0};var
row1xE2E5=new Array(4);for(var
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),row1xD2D5,0,3,row1xE2E5,0,3 ));data.pA7E=cA7E;};

function myIsNaN(x){return(isNaN(x)||(typeof
x=='number'&&!isFinite(x)));};function
eeparseFloat(str){str=String(str).replace(eedecreg ,".");var
res=parseFloat(str);if(isNaN(res)){return 0;}else{return
res;}};function eedisplayFloat(x){if(myIsNaN(x)){return
Number.NaN;}else{return String(x).replace(/\./g,eedec);}};function
lookup3vv(key,kvect,kfrom_start,kto_start,vvect,vf rom_,vto_){var
current=0;var from_=kfrom_start;var
to_=kto_start+1;while(true){current=(from_+to_)>>1 ;if(kvect[current]==key)break;if(from_==to_-1)break;if(kvect[current]<key){from_=current;}else{to_=current;}};while(cur rent<kto_start){if(kvect[current]==kvect[current+1]){current++;}else{break;};};if(key<kvect[current])return
Number.NaN;return vvect[vfrom_+current-kfrom_start]};
</script>

Feb 2 '06 #1
1 2134

"UKuser" <sp********@yahoo.co.uk> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.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\"><tr>";

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.Application") 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($exlRange->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($exlRange->Row ,$j);
$result[$sheetName]["ROW"][$finding - 1][$j - 1] = $cell->Text;
}

}

}

}

$exlBook->Close(false);
unset($exlSheets);
$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="javascript">

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

co.pA7D=eeparseFloat(document.formc.pA7D.value);ca lc(co);document.formc.pA7E.value=eedisplayFloat(co .pA7E);
};};

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

var row1xD2D5=new Array(4);for(var jj=0;jj<4;jj++){row1xD2D5[jj]=0};var
row1xE2E5=new Array(4);for(var
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),row1xD2D5,0,3,row1xE2E5,0,3 ));data.pA7E=cA7E;};

function myIsNaN(x){return(isNaN(x)||(typeof
x=='number'&&!isFinite(x)));};function
eeparseFloat(str){str=String(str).replace(eedecreg ,".");var
res=parseFloat(str);if(isNaN(res)){return 0;}else{return
res;}};function eedisplayFloat(x){if(myIsNaN(x)){return
Number.NaN;}else{return String(x).replace(/\./g,eedec);}};function
lookup3vv(key,kvect,kfrom_start,kto_start,vvect,vf rom_,vto_){var
current=0;var from_=kfrom_start;var
to_=kto_start+1;while(true){current=(from_+to_)>>1 ;if(kvect[current]==key)break;if(from_==to_-1)break;if(kvect[current]<key){from_=current;}else{to_=current;}};while(cur rent<kto_start){if(kvect[current]==kvect[current+1]){current++;}else{break;};};if(key<kvect[current])return
Number.NaN;return 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
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...
1
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...
4
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...
3
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...
3
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...
6
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...
1
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...
11
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...
4
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.