Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-25049

Cannot use excellib.class.php's write_url method - fails with mb_strlen error


    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.10
    • Fix Version/s: None
    • Component/s: General, Libraries
    • Labels:
    • Environment:
      LAMP, all up to date, Moodle 1.9.10+ (Build: 20101101)
    • Affected Branches:


      I am using some copy-and-pasted code (from /mod/survey/download.php) to export an Excel spreadsheet.

      I was previously using the write_string method but changed one instance to write_url which (apparently) takes the same arguments

      When I opened the spreadsheet I received the following error:

      Warning: mb_strlen() expects parameter 1 to be string, object given in /var/www/sdcmoodle/lib/pear/Spreadsheet/Excel/Writer/Worksheet.php on line 1542
      Catchable fatal error: Object of class Spreadsheet_Excel_Writer_Format could not be converted to string in /var/www/sdcmoodle/lib/pear/Spreadsheet/Excel/Writer/Worksheet.php on line 1567

      Looking through the code, write_url (http://xref.moodle.org/nav.html?lib/excellib.class.php.source.html#l172) calls pear_excel_worksheet->writeUrl (http://xref.moodle.org/nav.html?lib/pear/Spreadsheet/Excel/Writer/Worksheet.php.source.html#l1791) with four arguments, wereas it appears it should take 5.

      It may be that the following patch needs to be applied, so at least the correct number of arguments are being passed through (even though the end result is still gibberish):
      @@ -177,11 +177,11 @@ class MoodleExcelWorksheet {

      • @param string $url The url to write
      • @param mixed $format The XF format for the cell
      • function write_url($row, $col, $url, $format=null) {
        + function write_url($row, $col, $url, $string='', $format=null) { /// Calculate the internal PEAR format $format = $this->MoodleExcelFormat2PearExcelFormat($format); /// Add the url safely to the PEAR Worksheet - $this->pear_excel_worksheet->writeUrl($row, $col, $url, $format); + $this->pear_excel_worksheet->writeUrl($row, $col, $url, $string, $format); }


      This bug directly relates to MDL-13496 and MDL-19864.

        Gliffy Diagrams


          vaughany Paul Vaughan created issue -
          vaughany Paul Vaughan made changes -
          Field Original Value New Value
          Attachment diff.txt [ 22106 ]
          dougiamas Martin Dougiamas made changes -
          Workflow jira [ 40028 ] MDL Workflow [ 47021 ]
          dougiamas Martin Dougiamas made changes -
          Workflow MDL Workflow [ 47021 ] MDL Full Workflow [ 75231 ]
          salvetore Michael de Raadt made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Won't Fix [ 2 ]


            • Votes:
              0 Vote for this issue
              1 Start watching this issue


              • Created: