Bug #1831 - Upgrading of the PEAR's package Spreadsheet_Excel_Writer to version 0.9.2. Local changes about Excel export have been made in order defferent input encodings to be supported.

skala
Ivan Tcholakov 16 years ago
parent 684680cac0
commit 9cad2e22cb
  1. 2
      main/exercice/exercise_result.class.php
  2. 2
      main/gradebook/gradebook_result.class.php
  3. 2
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer.php
  4. 23
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php
  5. 14
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Format.php
  6. 48
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Parser.php
  7. 171
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Workbook.php
  8. 72
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Worksheet.php
  9. 16
      main/survey/survey.lib.php

@ -317,9 +317,11 @@ class ExerciseResult
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php');
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8
$workbook->send($filename);
$worksheet =& $workbook->addWorksheet('Report '.date('YmdGis'));
$worksheet->setInputEncoding(api_get_system_encoding());
$line = 0;
$column = 0; //skip the first column (row titles)

@ -238,10 +238,12 @@ class GradeBookResult
//build the results
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8); // BIFF8
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$worksheet =& $workbook->addWorksheet('Report '.gmdate('YmdGis'));
$worksheet->setInputEncoding(api_get_system_encoding());
$line = 0;
$column = 0; //skip the first column (row titles)
//headers

@ -32,7 +32,7 @@
*/
//require_once(api_get_path(LIBRARY_PATH).'pear/PEAR.php');
require_once('Writer/Workbook.php');
require_once 'Writer/Workbook.php';
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.

@ -84,6 +84,12 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
*/
var $_limit;
/**
* The temporary dir for storing the OLE file
* @var string
*/
var $_tmp_dir;
/**
* Constructor
*
@ -95,6 +101,7 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
$this->_data = '';
$this->_datasize = 0;
$this->_limit = 2080;
$this->_tmp_dir = '';
// Set the byte order
$this->_setByteOrder();
}
@ -234,5 +241,21 @@ class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
return $tmp;
}
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
}
?>

@ -429,7 +429,7 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$header = pack("vv", $record, $length);
$rotation = 0x00;
$rotation = $this->_rotation;
$biff8_options = 0x00;
$data = pack("vvvC", $ifnt, $ifmt, $style, $align);
$data .= pack("CCC", $rotation, $biff8_options, $used_attrib);
@ -996,13 +996,25 @@ class Spreadsheet_Excel_Writer_Format extends PEAR
$this->_rotation = 0;
break;
case 90:
if ($this->_BIFF_version == 0x0500) {
$this->_rotation = 3;
} elseif ($this->_BIFF_version == 0x0600) {
$this->_rotation = 180;
}
break;
case 270:
if ($this->_BIFF_version == 0x0500) {
$this->_rotation = 2;
} elseif ($this->_BIFF_version == 0x0600) {
$this->_rotation = 90;
}
break;
case -1:
if ($this->_BIFF_version == 0x0500) {
$this->_rotation = 1;
} elseif ($this->_BIFF_version == 0x0600) {
$this->_rotation = 255;
}
break;
default :
return $this->raiseError("Invalid value for angle.".

@ -92,6 +92,10 @@ define('SPREADSHEET_EXCEL_WRITER_EQ', "=");
*/
define('SPREADSHEET_EXCEL_WRITER_NE', "<>");
/**
* * @const SPREADSHEET_EXCEL_WRITER_CONCAT token identifier for character "&"
*/
define('SPREADSHEET_EXCEL_WRITER_CONCAT', "&");
require_once 'PEAR.php';
@ -663,10 +667,10 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
* @access private
* @param string $range An Excel range in the A1:A2 or A1..A2 format.
*/
function _convertRange2d($range)
function _convertRange2d($range, $class=0)
{
$class = 2; // as far as I know, this is magick.
// TODO: possible class value 0,1,2 check Formula.pm
// Split the range into 2 cell refs
if (preg_match("/^([A-Ia-i]?[A-Za-z])(\d+)\:([A-Ia-i]?[A-Za-z])(\d+)$/", $range)) {
list($cell1, $cell2) = split(':', $range);
@ -1203,10 +1207,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
case SPREADSHEET_EXCEL_WRITER_NE:
return $token;
break;
case SPREADSHEET_EXCEL_WRITER_CONCAT:
return $token;
break;
default:
// if it's a reference
if (preg_match('/^\$?[A-Ia-i]?[A-Za-z]\$?[0-9]+$/',$token) and
!ereg("[0-9]",$this->_lookahead) and
!preg_match("/[0-9]/",$this->_lookahead) and
($this->_lookahead != ':') and ($this->_lookahead != '.') and
($this->_lookahead != '!'))
{
@ -1214,56 +1221,56 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
}
// If it's an external reference (Sheet1!A1 or Sheet1:Sheet2!A1)
elseif (preg_match("/^\w+(\:\w+)?\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and
!ereg("[0-9]",$this->_lookahead) and
!preg_match("/[0-9]/",$this->_lookahead) and
($this->_lookahead != ':') and ($this->_lookahead != '.'))
{
return $token;
}
// If it's an external reference ('Sheet1'!A1 or 'Sheet1:Sheet2'!A1)
elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\![A-Ia-i]?[A-Za-z][0-9]+$/u",$token) and
!ereg("[0-9]",$this->_lookahead) and
!preg_match("/[0-9]/",$this->_lookahead) and
($this->_lookahead != ':') and ($this->_lookahead != '.'))
{
return $token;
}
// if it's a range (A1:A2)
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
!ereg("[0-9]",$this->_lookahead))
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
!preg_match("/[0-9]/",$this->_lookahead))
{
return $token;
}
// if it's a range (A1..A2)
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
!ereg("[0-9]",$this->_lookahead))
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token) and
!preg_match("/[0-9]/",$this->_lookahead))
{
return $token;
}
// If it's an external range like Sheet1!A1 or Sheet1:Sheet2!A1:B2
elseif (preg_match("/^\w+(\:\w+)?\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and
!ereg("[0-9]",$this->_lookahead))
!preg_match("/[0-9]/",$this->_lookahead))
{
return $token;
}
// If it's an external range like 'Sheet1'!A1 or 'Sheet1:Sheet2'!A1:B2
elseif (preg_match("/^'[\w -]+(\:[\w -]+)?'\!([A-Ia-i]?[A-Za-z])?[0-9]+:([A-Ia-i]?[A-Za-z])?[0-9]+$/u",$token) and
!ereg("[0-9]",$this->_lookahead))
!preg_match("/[0-9]/",$this->_lookahead))
{
return $token;
}
// If it's a number (check that it's not a sheet name or range)
elseif (is_numeric($token) and
elseif (is_numeric($token) and
(!is_numeric($token.$this->_lookahead) or ($this->_lookahead == '')) and
($this->_lookahead != '!') and ($this->_lookahead != ':'))
{
return $token;
}
// If it's a string (of maximum 255 characters)
elseif (ereg("^\"[^\"]{0,255}\"$",$token))
elseif (preg_match("/^\"[^\"]{0,255}\"$/",$token))
{
return $token;
}
// if it's a function call
elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$token) and ($this->_lookahead == "("))
elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$token) and ($this->_lookahead == "("))
{
return $token;
}
@ -1347,6 +1354,13 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return $result2;
}
$result = $this->_createTree('ptgNE', $result, $result2);
} elseif ($this->_current_token == SPREADSHEET_EXCEL_WRITER_CONCAT) {
$this->_advance();
$result2 = $this->_expression();
if (PEAR::isError($result2)) {
return $result2;
}
$result = $this->_createTree('ptgConcat', $result, $result2);
}
return $result;
}
@ -1363,7 +1377,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
function _expression()
{
// If it's a string return a string node
if (ereg("^\"[^\"]{0,255}\"$", $this->_current_token)) {
if (preg_match("/^\"[^\"]{0,255}\"$/", $this->_current_token)) {
$result = $this->_createTree($this->_current_token, '', '');
$this->_advance();
return $result;
@ -1493,7 +1507,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return $result;
}
// if it's a range
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or
elseif (preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token) or
preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+\.\.(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$this->_current_token))
{
$result = $this->_current_token;
@ -1521,7 +1535,7 @@ class Spreadsheet_Excel_Writer_Parser extends PEAR
return $result;
}
// if it's a function call
elseif (eregi("^[A-Z0-9\xc0-\xdc\.]+$",$this->_current_token))
elseif (preg_match("/^[A-Z0-9\xc0-\xdc\.]+$/i",$this->_current_token))
{
$result = $this->_func();
return $result;

@ -32,12 +32,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Format.php');
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php');
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Worksheet.php');
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Parser.php');
require_once(api_get_path(LIBRARY_PATH).'pear/OLE/PPS/Root.php');
require_once(api_get_path(LIBRARY_PATH).'pear/OLE/PPS/File.php');
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Format.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Worksheet.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Parser.php';
require_once api_get_path(LIBRARY_PATH).'pear/OLE/PPS/Root.php';
require_once api_get_path(LIBRARY_PATH).'pear/OLE/PPS/File.php';
/**
* Class for generating Excel Spreadsheets
@ -159,12 +159,6 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
*/
var $_country_code;
/**
* The temporary dir for storing the OLE file
* @var string
*/
var $_tmp_dir;
/**
* number of bytes for sizeinfo of strings
* @var integer
@ -207,7 +201,6 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_str_unique = 0;
$this->_str_table = array();
$this->_setPaletteXl97();
$this->_tmp_dir = '';
}
/**
@ -276,6 +269,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_tmp_format->_BIFF_version = $version;
$this->_url_format->_BIFF_version = $version;
$this->_parser->_BIFF_version = $version;
$this->_codepage = 0x04B0;
$total_worksheets = count($this->_worksheets);
// change version for all worksheets too
@ -343,8 +337,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_activesheet, $this->_firstsheet,
$this->_str_total, $this->_str_unique,
$this->_str_table, $this->_url_format,
$this->_parser);
$this->_parser, $this->_tmp_dir);
$this->_worksheets[$index] = &$worksheet; // Store ref for iterator
$this->_sheetnames[$index] = $name; // Store EXTERNSHEET names
$this->_parser->setExtSheet($name, $index); // Register worksheet name with parser
@ -375,7 +369,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
*/
function &addValidator()
{
include_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Validator.php');
include_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Validator.php';
/* FIXME: check for successful inclusion*/
$valid = new Spreadsheet_Excel_Writer_Validator($this->_parser);
return $valid;
@ -495,6 +489,10 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
*/
function _storeWorkbook()
{
if (count($this->_worksheets) == 0) {
return true;
}
// Ensure that at least one worksheet has been selected.
if ($this->_activesheet == 0) {
$this->_worksheets[0]->selected = 1;
@ -559,22 +557,6 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
return true;
}
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
/**
* Store the workbook in an OLE container
*
@ -583,7 +565,11 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
*/
function _storeOLEFile()
{
$OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
if($this->_BIFF_version == 0x0600) {
$OLE = new OLE_PPS_File(OLE::Asc2Ucs('Workbook'));
} else {
$OLE = new OLE_PPS_File(OLE::Asc2Ucs('Book'));
}
if ($this->_tmp_dir != '') {
$OLE->setTempDir($this->_tmp_dir);
}
@ -1311,9 +1297,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
8228 : Maximum Excel97 block size
-4 : Length of block header
-8 : Length of additional SST header information
= 8216
-8 : Arbitrary number to keep within _add_continue() limit = 8208
*/
$continue_limit = 8216;
$continue_limit = 8208;
$block_length = 0;
$written = 0;
$this->_block_sizes = array();
@ -1321,6 +1307,9 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
foreach (array_keys($this->_str_table) as $string) {
$string_length = strlen($string);
$headerinfo = unpack("vlength/Cencoding", $string);
$encoding = $headerinfo["encoding"];
$split_string = 0;
// Block length is the total length of the strings that will be
// written out in a single SST or CONTINUE block.
@ -1347,16 +1336,39 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
boundaries. Therefore, in some cases we need to reduce the
amount of available
*/
$align = 0;
// Only applies to Unicode strings
if ($encoding == 1) {
// Min string + header size -1
$header_length = 4;
if ($space_remaining > $header_length) {
// String contains 3 byte header => split on odd boundary
if (!$split_string && $space_remaining % 2 != 1) {
$space_remaining--;
$align = 1;
}
// Split section without header => split on even boundary
else if ($split_string && $space_remaining % 2 == 1) {
$space_remaining--;
$align = 1;
}
$split_string = 1;
}
}
if ($space_remaining > $header_length) {
// Write as much as possible of the string in the current block
$written += $space_remaining;
// Reduce the current block length by the amount written
$block_length -= $continue_limit - $continue;
$block_length -= $continue_limit - $continue - $align;
// Store the max size for this block
$this->_block_sizes[] = $continue_limit;
$this->_block_sizes[] = $continue_limit - $align;
// If the current string was split then the next CONTINUE block
// should have the string continue flag (grbit) set unless the
@ -1398,13 +1410,19 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
This length is required to set the offsets in the BOUNDSHEET records since
they must be written before the SST records
*/
$total_offset = array_sum($this->_block_sizes);
// SST information
$total_offset += 8;
if (!empty($this->_block_sizes)) {
$total_offset += (count($this->_block_sizes)) * 4; // add CONTINUE headers
$tmp_block_sizes = array();
$tmp_block_sizes = $this->_block_sizes;
$length = 12;
if (!empty($tmp_block_sizes)) {
$length += array_shift($tmp_block_sizes); // SST
}
return $total_offset;
while (!empty($tmp_block_sizes)) {
$length += 4 + array_shift($tmp_block_sizes); // CONTINUEs
}
return $length;
}
/**
@ -1421,9 +1439,31 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
function _storeSharedStringsTable()
{
$record = 0x00fc; // Record identifier
$length = 0x0008; // Number of bytes to follow
$total = 0x0000;
// Iterate through the strings to calculate the CONTINUE block sizes
$continue_limit = 8208;
$block_length = 0;
$written = 0;
$continue = 0;
// sizes are upside down
$this->_block_sizes = array_reverse($this->_block_sizes);
$length = array_pop($this->_block_sizes) + 8; // First block size plus SST information
$tmp_block_sizes = $this->_block_sizes;
// $tmp_block_sizes = array_reverse($this->_block_sizes);
// The SST record is required even if it contains no strings. Thus we will
// always have a length
//
if (!empty($tmp_block_sizes)) {
$length = 8 + array_shift($tmp_block_sizes);
}
else {
// No strings
$length = 8;
}
// Write the SST block header information
$header = pack("vv", $record, $length);
@ -1431,18 +1471,14 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$this->_append($header . $data);
// Iterate through the strings to calculate the CONTINUE block sizes
$continue_limit = 8216;
$block_length = 0;
$written = 0;
$continue = 0;
/* TODO: not good for performance */
foreach (array_keys($this->_str_table) as $string) {
$string_length = strlen($string);
$encoding = 0; // assume there are no Unicode strings
$headerinfo = unpack("vlength/Cencoding", $string);
$encoding = $headerinfo["encoding"];
$split_string = 0;
// Block length is the total length of the strings that will be
@ -1473,6 +1509,30 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
// Unicode data should only be split on char (2 byte) boundaries.
// Therefore, in some cases we need to reduce the amount of available
// space by 1 byte to ensure the correct alignment.
$align = 0;
// Only applies to Unicode strings
if ($encoding == 1) {
// Min string + header size -1
$header_length = 4;
if ($space_remaining > $header_length) {
// String contains 3 byte header => split on odd boundary
if (!$split_string && $space_remaining % 2 != 1) {
$space_remaining--;
$align = 1;
}
// Split section without header => split on even boundary
else if ($split_string && $space_remaining % 2 == 1) {
$space_remaining--;
$align = 1;
}
$split_string = 1;
}
}
if ($space_remaining > $header_length) {
// Write as much as possible of the string in the current block
@ -1483,7 +1543,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
$string = substr($string, $space_remaining);
// Reduce the current block length by the amount written
$block_length -= $continue_limit - $continue;
$block_length -= $continue_limit - $continue - $align;
// If the current string was split then the next CONTINUE block
// should have the string continue flag (grbit) set unless the
@ -1503,7 +1563,8 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
// Write the CONTINUE block header
if (!empty($this->_block_sizes)) {
$record = 0x003C;
$length = array_pop($this->_block_sizes);
$length = array_shift($tmp_block_sizes);
$header = pack('vv', $record, $length);
if ($continue) {
$header .= pack('C', $encoding);
@ -1524,5 +1585,7 @@ class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwri
}
}
}
}
?>

@ -32,8 +32,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Parser.php');
require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php');
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Parser.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php';
/**
* Class for generating Excel Spreadsheets
@ -364,13 +364,15 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
* @param mixed &$firstsheet The first worksheet in the workbook we belong to
* @param mixed &$url_format The default format for hyperlinks
* @param mixed &$parser The formula parser created for the Workbook
* @param string $tmp_dir The path to the directory for temporary files
* @access private
*/
function Spreadsheet_Excel_Writer_Worksheet($BIFF_version, $name,
$index, &$activesheet,
&$firstsheet, &$str_total,
&$str_unique, &$str_table,
&$url_format, &$parser)
&$url_format, &$parser,
$tmp_dir)
{
// It needs to call its parent's constructor explicitly
$this->Spreadsheet_Excel_Writer_BIFFwriter();
@ -460,6 +462,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$this->_input_encoding = '';
$this->_dv = array();
$this->_tmp_dir = $tmp_dir;
$this->_initialize();
}
@ -473,14 +477,32 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
*/
function _initialize()
{
if ($this->_using_tmpfile == false) {
return;
}
if ($this->_tmp_dir === '' && ini_get('open_basedir') === false) {
// open_basedir restriction in effect - store data in memory
// ToDo: Let the error actually have an effect somewhere
$this->_using_tmpfile = false;
return new PEAR_Error('Temp file could not be opened since open_basedir restriction in effect - please use setTmpDir() - using memory storage instead');
}
// Open tmp file for storing Worksheet data
$fh = tmpfile();
if ($fh) {
// Store filehandle
$this->_filehandle = $fh;
if ($this->_tmp_dir === '') {
$fh = tmpfile();
} else {
// For people with open base dir restriction
$tmpfilename = tempnam($this->_tmp_dir, "Spreadsheet_Excel_Writer");
$fh = @fopen($tmpfilename, "w+b");
}
if ($fh === false) {
// If tmpfile() fails store data in memory
$this->_using_tmpfile = false;
} else {
// Store filehandle
$this->_filehandle = $fh;
}
}
@ -1155,9 +1177,6 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
} elseif (preg_match("/^=/", $token)) {
// Match formula
return $this->writeFormula($row, $col, $token, $format);
} elseif (preg_match("/^@/", $token)) {
// Match formula
return $this->writeFormula($row, $col, $token, $format);
} elseif ($token == '') {
// Match blank
return $this->writeBlank($row, $col, $format);
@ -1514,7 +1533,10 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
*/
function setInputEncoding($encoding)
{
if ($encoding != 'UTF-16LE' && !function_exists('iconv')) {
// Modified by Ivan Tcholakov, 06-AUG-2010.
//if ($encoding != 'UTF-16LE' && !function_exists('iconv')) {
if (!api_equal_encodings($encoding, 'UTF-16LE') && !api_is_encoding_supported($encoding)) {
//
$this->raiseError("Using an input encoding other than UTF-16LE requires PHP support for iconv");
}
$this->_input_encoding = $encoding;
@ -1537,15 +1559,25 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
*/
function writeStringBIFF8($row, $col, $str, $format = null)
{
if ($this->_input_encoding == 'UTF-16LE')
// Modified by Ivan Tcholakov, 06-AUG-2010.
//if ($this->_input_encoding == 'UTF-16LE')
if (api_equal_encodings($this->_input_encoding, 'UTF-16LE'))
//
{
$strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
// Modified by Ivan Tcholakov, 06-AUG-2010.
//$strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
$strlen = api_is_encoding_supported('UTF-16LE') ? api_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
//
$encoding = 0x1;
}
elseif ($this->_input_encoding != '')
{
$str = iconv($this->_input_encoding, 'UTF-16LE', $str);
$strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
// Modified by Ivan Tcholakov, 06-AUG-2010.
//$str = iconv($this->_input_encoding, 'UTF-16LE', $str);
//$strlen = function_exists('mb_strlen') ? mb_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
$str = api_convert_encoding($str, 'UTF-16LE', $this->_input_encoding);
$strlen = api_is_encoding_supported('UTF-16LE') ? api_strlen($str, 'UTF-16LE') : (strlen($str) / 2);
//
$encoding = 0x1;
}
else
@ -2879,7 +2911,7 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$colcount = count($this->_colinfo);
for ($i = 0; $i < $colcount; $i++) {
// Skip cols without outline level info.
if (count($col_level) >= 6) {
if (count($this->_colinfo[$i]) >= 6) {
$col_level = max($this->_colinfo[$i][5], $col_level);
}
}
@ -2895,8 +2927,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$col_level++;
}
$header = pack("vv", $record, $length);
$data = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
$header = pack("vv", $record, $length);
$data = pack("vvvv", $dxRwGut, $dxColGut, $row_level, $col_level);
$this->_prepend($header.$data);
}
@ -2940,8 +2972,8 @@ class Spreadsheet_Excel_Writer_Worksheet extends Spreadsheet_Excel_Writer_BIFFwr
$grbit |= 0x0400; // Outline symbols displayed
}
$header = pack("vv", $record, $length);
$data = pack("v", $grbit);
$header = pack("vv", $record, $length);
$data = pack("v", $grbit);
$this->_prepend($header . $data);
}

@ -2768,9 +2768,9 @@ class SurveyUtil {
FROM $table_survey_question q LEFT JOIN $table_survey_question_option o
ON q.question_id = o.question_id
WHERE q.survey_id = '".Database::escape_string($_GET['survey_id'])."'
GROUP BY q.question_id
GROUP BY q.question_id
ORDER BY q.sort ASC";
// </hub>
// </hub>
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
// We show the questions if
@ -2837,11 +2837,11 @@ class SurveyUtil {
}
else if ($row['type'] == 'percentage' && $display_percentage_header) {
echo '<th>&nbsp;%&nbsp;</th>';
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$display_percentage_header = 0;
}
else if ($row['type'] == 'percentage') {
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
}
else if ($row['type'] <> 'comment' AND $row['type'] <> 'pagebreak' AND $row['type'] <> 'percentage')
{
@ -2928,7 +2928,7 @@ class SurveyUtil {
echo '<td align="center">';
echo $answers_of_user[$question_id]['0']['option_id'];
echo '</td>';
}
}
else {
foreach ($possible_option as $option_id => & $value) {
if ($questions[$question_id]['type'] == 'percentage') {
@ -2938,12 +2938,12 @@ class SurveyUtil {
echo "</td>";
}
}
else {
else {
echo '<td align="center">';
if (!empty($answers_of_user[$question_id][$option_id])) {
if ($answers_of_user[$question_id][$option_id]['value'] != 0) {
echo $answers_of_user[$question_id][$option_id]['value'];
}
}
else {
echo 'v';
}
@ -3158,7 +3158,9 @@ class SurveyUtil {
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report 1');
$worksheet->setInputEncoding(api_get_system_encoding());
$line = 0;
$column = 1; // Skip the first column (row titles)

Loading…
Cancel
Save