Jump to content


Photo

PHP to excel spreadsheet help


  • Please log in to reply
5 replies to this topic

#1 patto

patto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 July 2006 - 01:51 AM

I have recently got a webpage PHP script and i am wanting the calculator that the script runs into an excell spreadsheet or a program can anyone offer any advice or what programs to use and/or what to do.

THanx patto

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 14 July 2006 - 01:58 AM

What your asking doesn't really make sense.  Please clarify.

Unless you are using a Microsoft server and can use COM there is no want to output a .xls file.  However, you can output a comma delimited file (CSV) that will open in Excel without COM.

#3 patto

patto
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 July 2006 - 03:09 AM

Sorry, lol new to this dont really know what to say

Ok i have been using a website for a special calculator which gives you answers to catenary curves and i have emailed them asking for a copy for personal use and they have sent me the PHP scripted webpage and what i want to do is chage it from a webpage to a microsoft excel spreadsheet or somehow use the page they have sent me and set it up so the calculator works without the internet.

i hope this makes more sense

i believe this is the scripting that amkes the calculator works


0)) $F = $_GET['F']; else $F = 0.674427074; if (isset($_GET['g']) && ($_GET['g'] + 0 > 0)) $g = $_GET['g']; else $g = 32.185039370; if (isset($_GET['q']) && ($_GET['q'] + 0 > 0)) $q = $_GET['q']; else $q = 0.00049999; if (isset($_GET['a']) && ($_GET['a'] + 0 > 0)) $a = $_GET['a']; else $a = 1.640419948; } // perform calculations in Imperial $H = $F/$g; $lambda = $H/$q; $x = (exp($a/(2*$lambda)) - exp(-$a/(2*$lambda))) / 2; $l = 2*$lambda*$x; $f = ($a/4)*sqrt(6*(($l/$a)-1)); $oF = $F; $F = $F*4.44822/(0.4536*0.3048); $sag = $lambda * (cosh($a/(2*$lambda)) - 1); $S = 2*$lambda*sinh($a/(2*$lambda)); $err = (($S/$a) - 1)*100; $F = $oF; if (($a == 0) or ($F == 0) or ($q == 0)) { $f = 0; $percent_error = 0; } else { $percent_error = ((($l/$a)-1)*100)/2; } // convert answers from metric to Imperial $l = $l/0.0254/12; $f = $f/0.0254/12; ?>

and here is the link to the actual website calculator.
http://www.spaceagec...om/calccabm.htm

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 July 2006 - 01:06 AM

You may want to check with the creator of the code to make sure that they will allow you to use it a different way.

In order to do what you want...take that block of code and have it execute inside of an excel spreadsheet, you will have to rewrite it from php to vbscript, as a macro in excel.

#5 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 01:54 AM

It mainly depends what the output is to be, if it's a spreadsheet grid then you can convert to Excel CSV, DIF or XML. XML gives you the most options without having to use anything other than standard PHP functions.

If it's graphs etc. that you want in the spreadsheet then it's a bit of a different matter.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 July 2006 - 11:04 AM

Adding a few linebreaks should clarify if. The first bit checks for valid input and substitutes default values where input is 0.

The second bit shows the formulae for your cells.

<?php
if (isset($_GET['F']) && ($_GET['F'] + 0 > 0)) 
	$F = $_GET['F']; 
else $F = 0.674427074; 
if (isset($_GET['g']) && ($_GET['g'] + 0 > 0)) 
	$g = $_GET['g']; 
else $g = 32.185039370; 
if (isset($_GET['q']) && ($_GET['q'] + 0 > 0)) 
	$q = $_GET['q']; 
else $q = 0.00049999; 
if (isset($_GET['a']) && ($_GET['a'] + 0 > 0)) 
	$a = $_GET['a']; 
else $a = 1.640419948; } 
// perform calculations in Imperial 
$H = $F/$g; 
$lambda = $H/$q; 
$x = (exp($a/(2*$lambda)) - exp(-$a/(2*$lambda))) / 2; 
$l = 2*$lambda*$x; 
$f = ($a/4)*sqrt(6*(($l/$a)-1)); 
$oF = $F; 
$F = $F*4.44822/(0.4536*0.3048); 
$sag = $lambda * (cosh($a/(2*$lambda)) - 1); 
$S = 2*$lambda*sinh($a/(2*$lambda)); 
$err = (($S/$a) - 1)*100; 
$F = $oF; 
if (($a == 0) or ($F == 0) or ($q == 0)) { 
	$f = 0; $percent_error = 0; 
} 
else { 
	$percent_error = ((($l/$a)-1)*100)/2; 
} 
// convert answers from metric to Imperial 
$l = $l/0.0254/12; 
$f = $f/0.0254/12;
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users