problem with messy code while setUrl in a cell

Jul 27, 2009 at 8:14 AM
Edited Jul 27, 2009 at 8:28 AM


I tried to insert hyperlink into cell G1, with the sheet name string converted from gb2312 to utf-8.

but, I got messy code while the mouse on the cell G1. I also can't goto the sheet I want to go after click the hyperlinked characters in cell G1.

I wonder whether phpexcel suport utf-8 while setUrl?

$mysheet = iconv('gb2312','utf-8',$mysheet);
$url = "sheet://".$mysheet."!A1";


I used function mb_convert_encoding to convert the code, and I got the same result.

Jul 27, 2009 at 8:27 AM
Edited Jul 27, 2009 at 8:28 AM


Jul 27, 2009 at 9:29 PM

>> I wonder whether phpexcel suport utf-8 while setUrl?

I just checked the code, and indeed you are right. There was a bug (assuming you were using Excel5 writer), but it should be fixed now.

Jul 28, 2009 at 2:44 AM

thank you koyama.


I used the following command to patch:


patch -R Worksheet.php wi-10352.patch

and I saw the result after the command:


(Stripping trailing CRs from patch.)
patching file /eprogram/estar/include/PHPexcel/PHPExcel/Writer/Excel5/Worksheet.php
Unreversed patch detected!  Ignore -R? [n] y
Hunk #1 succeeded at 1076 (offset -12 lines).


(Stripping trailing CRs from patch.)

patching file /eprogram/estar/include/PHPexcel/PHPExcel/Writer/Excel5/Worksheet.php

Unreversed patch detected!  Ignore -R? [n] y

Hunk #1 succeeded at 1076 (offset -12 lines).




and I also saw the change in Worksheet.php:


function _writeUrlInternal($row1, $col1, $row2, $col2, $url)
		$record	  = 0x01B8;					   // Record identifier
		$length	  = 0x00000;					  // Bytes to follow

		// Strip URL type
		$url = preg_replace('/^internal:/', '', $url);

		// Pack the undocumented parts of the hyperlink stream
		$unknown1	= pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");

		// Pack the option flags
		$options	 = pack("V", 0x08);

		// Convert the URL type and to a null terminated wchar string
		$url .= "\0";

		// character count
		$url_len = PHPExcel_Shared_String::CountCharacters($url);
		$url_len = pack('V', $url_len);

		$url = PHPExcel_Shared_String::ConvertEncoding($url, 'UTF-16LE', 'UTF-8');

		// Calculate the data length
		$length	  = 0x24 + strlen($url);

		// Pack the header data
		$header	  = pack("vv",   $record, $length);
		$data		= pack("vvvv", $row1, $row2, $col1, $col2);

		// Write the packed data
		$this->_append($header . $data .
					   $unknown1 . $options .
					   $url_len . $url);
		return 0;




but, I got an error while excuting:


Warning: Missing argument 2 for PHPExcel_Shared_String::CountCharacters(), called in /eprogram/estar/include/PHPexcel/PHPExcel/Writer/Excel5/Worksheet.php on line 1082 and defined in/eprogram/estar/include/PHPexcel/PHPExcel/Shared/String.php on line 253

Notice: Undefined variable: enc in /eprogram/estar/include/PHPexcel/PHPExcel/Shared/String.php on line 256
enc is: 

Jul 28, 2009 at 3:20 AM

ok, now I add the second argument to

$url_len = PHPExcel_Shared_String::CountCharacters($url, 'utf-8');

now, it works.

thank you!
Jul 28, 2009 at 10:59 PM

Ok, great, and if others are experiencing the same problem it should be working with latest source code:

Aug 25, 2009 at 4:29 PM
Edited Aug 25, 2009 at 4:33 PM

Hi guys,

I am getting a big headache by using the PHPExcel class. Why? Whenever I try to view the file generated by the PHPEXcel_Writer_Excel5 I cannot have the real file. MS Excel will tell me that the content of the file is different from the extension of the file which is  xls. And if it will display some fancy characters. I have tried the php function utf8encode and decode but still. I don't know what to do. The bad side is that I am building a banking software. Please help me before the world collapse on me.

I am generating the excel file from a php array.



Aug 25, 2009 at 4:41 PM

@BigToch: Is this only happening with PHPExcel_Writer_Excel5, or is it also happening with PHPExcel_Writer_Excel2007? Also, are you saving file to disk, or are you sending file via HTTP to client browser for download?