View Issue Details

This bug affects 1 person(s).
 2
IDProjectCategoryView StatusLast Update
07654Bug reportsStatisticspublic2013-03-17 12:12
Reporterslansky Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.00+ 
Fixed in Version2.00+ 
Summary07654: Numers in Excel export
Description

Statistics export uses for exporting code:
$this->sheet->write($this->xlsRow...

This is problem for exporting in internatinalized environment where we can use other number formats (Czech uses decimal comma) and Excel does not recognise those as numbers but as strings.

Better way is using $this->sheet->writeNumber(... with appropriate format.

Other parts of LS may be affected as well.

Additional Information

In the attachment is a patch dealing with this issue in statistics export. Needs some code cleanup.

TagsNo tags attached.
Attached Files
statistics_helper.php.patch (8,261 bytes)   
Index: statistics_helper.php
===================================================================
--- statistics_helper.php	(revision 232)
+++ statistics_helper.php	(revision 233)
@@ -574,6 +574,8 @@
       */
      protected $sheet;
      
+     protected $xlsPercents;
+     
      /**
       * The current Excel workbook we are working on
       * 
@@ -2343,8 +2345,8 @@
 
                         $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':
@@ -2443,8 +2445,8 @@
 
                                 $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':
@@ -2505,9 +2507,9 @@
 
                                 $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':
@@ -2575,9 +2577,9 @@
 
                                 $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':
@@ -2640,9 +2642,9 @@
 
                                 $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':
@@ -2702,13 +2704,13 @@
 
                                 $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':
@@ -2752,8 +2754,8 @@
 
                             $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':
@@ -2882,11 +2884,11 @@
 
                         $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':
@@ -3265,6 +3267,8 @@
 
             // 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="~|";
@@ -3320,16 +3324,16 @@
             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;
statistics_helper.php.patch (8,261 bytes)   
Bug heat2
Complete LimeSurvey version number (& build)130305
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMySQL 5.5.24, MySQL 5.1.6
Server OS (if known)Windows 7, Linux (Debian)
Webserver software & version (if known)Apache 2.2.22, Apache 2.2.16
PHP VersionPHP 5.3.1, PHP 5.3.3

Users monitoring this issue

There are no users monitoring this issue.

Activities

c_schmitz

c_schmitz

2013-03-11 15:25

administrator   ~24631

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11831

c_schmitz

c_schmitz

2013-03-11 15:25

administrator   ~24632

Thank you!

c_schmitz

c_schmitz

2013-03-12 12:36

administrator   ~24663

Fix committed to 2.05 branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=11840

c_schmitz

c_schmitz

2013-03-17 12:12

administrator   ~24724

New version released.

Related Changesets

LimeSurvey: master b0f3a2ac

2013-03-11 14:25:24

c_schmitz

Details Diff
Fixed issue 07654: Better handling of numbers in Excel export - patch by slansky Affected Issues
07654
mod - application/helpers/admin/statistics_helper.php Diff File

LimeSurvey: 2.05 122a5919

2013-03-11 14:25:24

c_schmitz

Details Diff
Fixed issue 07654: Better handling of numbers in Excel export - patch by slansky Affected Issues
07654
mod - application/helpers/admin/statistics_helper.php Diff File

Issue History

Date Modified Username Field Change
2013-03-11 13:01 slansky New Issue
2013-03-11 13:01 slansky File Added: statistics_helper.php.patch
2013-03-11 14:43 c_schmitz Assigned To => c_schmitz
2013-03-11 14:43 c_schmitz Status new => assigned
2013-03-11 15:25 c_schmitz Changeset attached => LimeSurvey master b0f3a2ac
2013-03-11 15:25 c_schmitz Note Added: 24631
2013-03-11 15:25 c_schmitz Resolution open => fixed
2013-03-11 15:25 c_schmitz Note Added: 24632
2013-03-11 15:25 c_schmitz Status assigned => resolved
2013-03-11 15:25 c_schmitz Fixed in Version => 2.00+
2013-03-12 12:36 c_schmitz Changeset attached => LimeSurvey 2.05 122a5919
2013-03-12 12:36 c_schmitz Note Added: 24663
2013-03-17 12:12 c_schmitz Note Added: 24724
2013-03-17 12:12 c_schmitz Status resolved => closed