Skip to content

Commit 7a34720

Browse files
Added initial files from google code's jQuery.sheet repo, where it incubated
1 parent 427a92d commit 7a34720

File tree

4 files changed

+653
-0
lines changed

4 files changed

+653
-0
lines changed

calc.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
ini_set('error_reporting', E_ALL);
4+
ini_set('display_errors', 1);
5+
6+
include_once '../parser/formula/formula.php';
7+
include_once 'handler.php';
8+
include_once 'formulas.php';
9+
10+
if (empty($_REQUEST['ss'])) {
11+
echo "Spreadsheet needed";
12+
exit();
13+
}
14+
15+
$spreadsheets = json_decode($_REQUEST['ss']);
16+
17+
$formulas = new formulas();
18+
19+
$handler = ParserHandler::initSimpleJson($spreadsheets, $formulas);
20+
$handler->calc();
21+
22+
if (isset($_REQUEST['c'])) {
23+
$cell = $_REQUEST['c'];
24+
$sheet = (isset($_REQUEST['s']) ? $_REQUEST['s'] : 0);
25+
$handler->setSheet($sheet);
26+
echo json_encode($handler->cellValue($cell));
27+
} else if (isset($_REQUEST['cr'])) {
28+
$cells = explode(':', $_REQUEST['cr']);
29+
$sheet = (isset($_REQUEST['s']) ? $_REQUEST['s'] : 0);
30+
$handler->setSheet($sheet);
31+
echo json_encode($handler->cellRangeValue($cells[0], $cells[1]));
32+
} else {
33+
echo json_encode($handler->toArray(isset($_REQUEST['s']) ? $_REQUEST['s'] : null));
34+
}

formulas.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
class formulas
3+
{
4+
public $inputs;
5+
public $outputs;
6+
7+
function sum($cell, $array)
8+
{
9+
return array_sum($array);
10+
}
11+
12+
function divide($cell, $array)
13+
{
14+
return array_sum($array);
15+
}
16+
17+
function average($cell, $array)
18+
{
19+
$total = 0;
20+
$count = count($array);
21+
foreach ($array as $value) {
22+
$total = $total + $value;
23+
}
24+
$average = ($total / $count);
25+
return $average;
26+
}
27+
28+
function avg($cell, $array)
29+
{
30+
return $this->average($cell, $array);
31+
}
32+
33+
function count($cell, $array)
34+
{
35+
$count = 0;
36+
37+
foreach ($array as $value) {
38+
if ($value != null) $count++;
39+
}
40+
41+
return $count;
42+
}
43+
44+
function counta($cell, $array)
45+
{
46+
$count = 0;
47+
48+
foreach ($array as $value) {
49+
if (!empty($value)) $count++;
50+
}
51+
52+
return $count;
53+
}
54+
55+
function max($cell, $array)
56+
{
57+
return max($array);
58+
}
59+
60+
function min($cell, $array)
61+
{
62+
return min($array);
63+
}
64+
65+
function mean($cell, $array)
66+
{
67+
sort($array);
68+
$count = count($array); //total numbers in array
69+
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
70+
if($count % 2) { // odd number, middle is the median
71+
$median = $array[$middleval];
72+
} else { // even number, calculate avg of 2 medians
73+
$low = $array[$middleval];
74+
$high = $array[$middleval+1];
75+
$median = (($low+$high)/2);
76+
}
77+
return $median;
78+
}
79+
80+
function abs($cell, $array)
81+
{
82+
return abs($array);
83+
}
84+
85+
function ceiling($cell, $array)
86+
{
87+
return ceil($array);
88+
}
89+
90+
function floor($cell, $array)
91+
{
92+
return floor($array);
93+
}
94+
95+
function int($cell, $array)
96+
{
97+
return floor($array);
98+
}
99+
100+
function round($cell, $array)
101+
{
102+
return round($array);
103+
}
104+
105+
function rand($cell, $array)
106+
{
107+
return rand();
108+
}
109+
110+
function rnd($cell, $array)
111+
{
112+
return $this->rand($cell, $array);
113+
}
114+
115+
function true($cell, $array)
116+
{
117+
return 'TRUE';
118+
}
119+
120+
function false($cell, $array)
121+
{
122+
return 'FALSE';
123+
}
124+
125+
function pi($cell, $array)
126+
{
127+
return pi();
128+
}
129+
130+
function power($cell, $array)
131+
{
132+
return pow($array[0], $array[1]);
133+
}
134+
135+
function sqrt($cell, $array)
136+
{
137+
return sqrt($array);
138+
}
139+
140+
function input($cell, $array)
141+
{
142+
return (!empty($this->inputs[$array[0]]) ? $this->inputs[$array[0]] : 0);
143+
}
144+
145+
function output($cell, $array)
146+
{
147+
$this->outputs[$array[0]] = (!empty($array[1]) ? $array[1] : 0);
148+
return '';
149+
}
150+
}

0 commit comments

Comments
 (0)