Sample PHP Code: Formula Calculation with Online Charting / Get chart

<?php

  $monthly_savings = $_REQUEST["Monthly_savings"];

  $annual_investment_growth_rate = $_REQUEST["Annual_Investment_growth_rate"];

  $annual_salary_increase_rate = $_REQUEST["Annual_Salary_Increase_Rate"];

 

  // Create an instance of the application

  $psc = new COM("PagosSpreadSheet.Application") or die("Pagos Spreadsheet component is not installed");

                 

  $psc->Workbooks()->Open(realpath("Spreadsheets/Retirement/Retirement_chart.xls"));

           

  $workbook = $psc->Workbooks->Item(1);

 

  $workbook->Names()->Item("Monthly_savings")->Range->Value = $monthly_savings;

  $workbook->Names()->Item("Annual_Investment_growth_rate")->Range->Value = $annual_investment_growth_rate;

  $workbook->Names()->Item("Annual_Salary_Increase_Rate")->Range->Value = $annual_salary_increase_rate;

 

  $filename = realpath("") . "\\Spreadsheets\\Temp\\RetirementChart" . rand(100, 1000) . ".gif";

 

  srand((double)microtime()*1000000);         

           

  //Save chart to a temporary file for streaming

  $workbook->Worksheets->Item(1)->ChartObjects->Item(1)->Chart->SaveAs($filename);

 

  // Close workbook

  $psc->Workbooks()->Close();

           

  //Stream chart to response

  header('Content-type: image/gif');

  readfile($filename);

 

  unlink($filename);

?>