-3

i'm a junior php developer, i have a form WHERE the user insert a input, like this

ACTIVITIES = for example: 5;
SERVICES =  for example: 10;
FEE = for example: 0.20;

with this inputs i'm calculating a total, like this:

TOTAL PAYMENT = (ACTIVITIES + SERVICE) * FEE = (5+10)*0.20 = 3 

i would like create a file excel, where user can download, like the image attached. enter image description here

i tried to EXPORT a table with PHP operation logic, my value $TOTAL = 3 work well !

PROBLEM: When i open file excel downloaded, i click on total result 3, i can not see the formula = (D5+D6)*D8 , it give me only value 3.

Can i fix this with PHP? other language? thank you for your help!

Diego Cespedes
  • 1,353
  • 4
  • 26
  • 47
  • 3
    Since you haven't shown how you generate your excel file, we can't help you. But I suspect you're **NOT** generating an Excel file, you're generating html and LYING to Excel about it being an actual native Excel file. – Marc B Oct 14 '16 at 15:08
  • @MarcB , yes maybe my question can be, is possible generate a file excel with php and show the formula ? – Diego Cespedes Oct 14 '16 at 15:12
  • 1
    If you'd bothered doing any kind of basic searching: http://stackoverflow.com/questions/10595599/which-is-the-best-way-to-generate-excel-output-in-php – Marc B Oct 14 '16 at 15:14

2 Answers2

0

Yeah, to output to excel you need to use a library. This is a good one.

https://phpexcel.codeplex.com/

I'm not sure it'll do the formula but the colours etc - yeah no probs.

Richard Housham
  • 1,525
  • 2
  • 15
  • 31
0

Try also EasyXLS library:

$excel = new COM("EasyXLS.ExcelDocument");

// Add a worksheet
$excel->easy_addWorksheet_2("Total payment");
$worksheet = $excel->easy_getSheet("Formula")->easy_getExcelTable();

// Add values and formula
$worksheet->easy_getCell_2("C5")->setValue("ACTIVITIES");
$worksheet->easy_getCell_2("D5")->setValue("5");

$worksheet->easy_getCell_2("C6")->setValue("SERVICES");
$worksheet->easy_getCell_2("D6")->setValue("10");

$worksheet->easy_getCell_2("C8")->setValue("FEE");
$worksheet->easy_getCell_2("D8")->setValue("0.2");

$worksheet->easy_getCell_2("C10")->setValue("TOTAL");
$worksheet->easy_getCell_2("D10")->setValue("=(D5+D6)*D8");

// Create Excel file
$excel->easy_WriteXLSFile("Total payment.xls");

For other formulas and more details read this http://www.easyxls.com/manual/basics/import-export-excel-formulas.html

alex.pulver
  • 2,107
  • 2
  • 31
  • 31