Formulas/converting from JS?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?


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

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


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

var row1xD2D5=new Array(4);for(var jj=0;jj<4;jj++);var
row1xE2E5=new Array(4);for(var
jj=0;jj<4;jj++);function calc(data){var

function myIsNaN(x){return(isNaN(x)||(typeof
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
current=0;var from_=kfrom_start;var
Number.NaN;return vvect[vfrom_+current-kfrom_start]};

Re: Formulas/converting from JS?

Quoted text here. Click to load it

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  
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.
// 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");
  $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 == "")

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

$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)

$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;




For more information, please visit my blog site (written in Chinese)

Quoted text here. Click to load it

Site Timeline