Skip to content

Commit

Permalink
Fixed issue #7654: Better handling of numbers in Excel export - patch…
Browse files Browse the repository at this point in the history
… by slansky
  • Loading branch information
c-schmitz committed Mar 12, 2013
1 parent 79cabcf commit 122a591
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -574,6 +574,8 @@ class statistics_helper {
*/
protected $sheet;

protected $xlsPercents;

/**
* The current Excel workbook we are working on
*
Expand Down Expand Up @@ -2343,8 +2345,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $gdata[$i]). "%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$gdata[$i]/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2443,8 +2445,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $percentage)."%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$percentage/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2505,9 +2507,9 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $percentage)."%");
$this->sheet->write($this->xlsRow,3,sprintf("%01.2f", $percentage)."%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$percentage/100, $this->xlsPercents);
$this->sheet->writeNumber($this->xlsRow,3,$percentage/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2575,9 +2577,9 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $percentage)."%");
$this->sheet->write($this->xlsRow,3,sprintf("%01.2f", $aggregatedgdata)."%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$percentage/100, $this->xlsPercents);
$this->sheet->writeNumber($this->xlsRow,3,$aggregatedgdata/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2640,9 +2642,9 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $percentage)."%");
$this->sheet->write($this->xlsRow,3,sprintf("%01.2f", $aggregatedgdata)."%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$percentage/100, $this->xlsPercents);
$this->sheet->writeNumber($this->xlsRow,3,$aggregatedgdata/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2702,13 +2704,13 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Sum")." (".$statlang->gT("Answers").")");
$this->sheet->write($this->xlsRow,1,$sumitems);
$this->sheet->write($this->xlsRow,2,$sumpercentage."%");
$this->sheet->write($this->xlsRow,3,$sumpercentage."%");
$this->sheet->writeNumber($this->xlsRow,1,$sumitems);
$this->sheet->writeNumber($this->xlsRow,2,$sumpercentage/100, $this->xlsPercents);
$this->sheet->writeNumber($this->xlsRow,3,$sumpercentage/100, $this->xlsPercents);
$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Number of cases"));
$this->sheet->write($this->xlsRow,1,$TotalCompleted);
$this->sheet->write($this->xlsRow,2,$casepercentage."%");
$this->sheet->writeNumber($this->xlsRow,1,$TotalCompleted);
$this->sheet->writeNumber($this->xlsRow,2,$casepercentage/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2752,8 +2754,8 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$label[$i]);
$this->sheet->write($this->xlsRow,1,$grawdata[$i]);
$this->sheet->write($this->xlsRow,2,sprintf("%01.2f", $gdata[$i])."%");
$this->sheet->writeNumber($this->xlsRow,1,$grawdata[$i]);
$this->sheet->writeNumber($this->xlsRow,2,$gdata[$i]/100, $this->xlsPercents);

break;
case 'pdf':
Expand Down Expand Up @@ -2882,11 +2884,11 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Arithmetic mean"));
$this->sheet->write($this->xlsRow,1,$am);
$this->sheet->writeNumber($this->xlsRow,1,$am);

$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Standard deviation"));
$this->sheet->write($this->xlsRow,1,$stddev);
$this->sheet->writeNumber($this->xlsRow,1,$stddev);

break;
case 'pdf':
Expand Down Expand Up @@ -3265,6 +3267,8 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr

// Creating the first worksheet
$this->sheet = $this->workbook->addWorksheet(utf8_decode('results-survey'.$surveyid));
$this->xlsPercents = &$this->workbook->addFormat();
$this->xlsPercents->setNumFormat('0.00%');
$this->sheet->setInputEncoding('utf-8');
$this->sheet->setColumn(0,20,20);
$separator="~|";
Expand Down Expand Up @@ -3320,16 +3324,16 @@ public function generate_statistics($surveyid, $allfields, $q2show='all', $usegr
case "xls":
$this->xlsRow = 0;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Number of records in this query:",'unescaped'));
$this->sheet->write($this->xlsRow,1,$results);
$this->sheet->writeNumber($this->xlsRow,1,$results);
$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Total records in survey:",'unescaped'));
$this->sheet->write($this->xlsRow,1,$total);
$this->sheet->writeNumber($this->xlsRow,1,$total);

if($total)
{
$this->xlsRow++;
$this->sheet->write($this->xlsRow,0,$statlang->gT("Percentage of total:",'unescaped'));
$this->sheet->write($this->xlsRow,1,$percent."%");
$this->sheet->writeNumber($this->xlsRow,1,$results/$total, $this->xlsPercents);
}

break;
Expand Down

0 comments on commit 122a591

Please sign in to comment.